Disclosure: This article may contain affiliate links. When you purchase, we may earn a commission.

Friday, April 14, 2023

Difference between URL, URI and URN - Interview Question

All three URI, URL, and URN are used to identify any resource or name on the internet, but there is a subtle difference between them. URI is the superset of both URL and URN. By the way, the main difference between URL and URI is protocol to retrieve the resource. URL always include a network protocol e.g. HTTP, HTTPS, FTP etc to retrieve a resource from its location. While URI, in case of URN just uniquely identifies the resource e.g. ISBN numbers which are a good example of URN is used to identify any book uniquely. In this article, we will briefly see what is URI, URL, and URN and then see the main difference between URI, URL, and URN.

What is URI
URI stands for Uniform Resource Identifier. URI is a text which is used to identify any resource or name on the Internet. URI has two specializations in the form of URL (Uniform Resource Locator) and URN (Uniform Resource Name) to identify resources and names. We mostly see examples of URL and URN in the real world. If you are working on JSP and familiar with using tag library e.g. display tag and JSTL core tag library, then you may remember the use of URI to locate binary corresponding to a tag library.

What is URL
URL standards for Uniform resource locator and it is a subset of URI or Uniform Resource Identifier. URL includes location as well as the protocol to retrieve the resource e.g. in http://java67.blogspot.sg/2012/09/what-is-new-in-java-7-top-5-jdk-7.html, HTTP is a protocol which can be used to retrieve resource what-is-new-in-java-7-top-5-jdk-7.html available in location http://java67.blogspot.com directory. It's not necessary that URL always include HTTP as protocol, it can use any protocol e.g. ftp://, https:// or ldap://.

What is URN
URN stands for Uniform Resource Name. URN is also the subset of URI. One of the best examples of URN is ISBN number which is used to uniquely identify a book. URN is completely different than URL as it doesn't include any protocol.


Difference between URI, URL, and URN

After knowing what is URI, URL, and URN, it's easy to find the difference between them. The main difference between URI and URL is that every URL is a URI but not vice versa. Similarly, every URN is a URI, but the opposite is not true. Another difference between URI and URL is that URL includes the protocol, which is key to retrieving information from any location. Here are few differences between URI, URL and URN in point format:

1) Every URL and URN is URI because URI is the superset of both URL and URN.

2) URL includes protocol e.g. http://, ftp:// along with location to identify resource e.g. http://www.blogspot.com/abc.html.

3) URN is the unambiguous way to identify a resource. ISBN numbers are the best examples of the URN.

Here is a diagram that clearly reflect the relationship of URL, URI, and URN on the internet:

Difference between URL and URI and URN

That's all on the difference between URI, URL, and URN. It’s good to know how much difference they are though you mostly need to deal with URL.

Other Interview questions from Java67 Blog


  1. I am still not clear about URN.
    Can you please confirm me, according to RFC 3986 is ":" (colon) is reserved character for URN ?

  2. You seem to have changed your closing diagram from what it was when this article was first posted (as seen here) ... and now it's incorrect. I think you've also changed some content (or possibly I didn't read closely enough the first time), as it's also incorrect.

    In your first paragraph, "the main difference between URL and URI is protocol," "URI" should be "URN" -- but this is not accurate. For a URL, the scheme (the part before the first colon, ":") is also a retrieval protocol; for URN, the scheme *may* be -- but is not necessarily -- a retrieval protocol.

    Later, in "What is URN?" you say "URN is completely different than URL as it doesn't include any protocol." As above, this is not accurate. URN scheme *may* not be a retrieval protocol -- but when a URI is both a URL *and* a URN, the scheme *is* a retrieval protocol.

    and that closing diagram...

    Left ellipse == URN (Name).
    Right ellipse == URL (Locator).
    Union == URI (Identifier).
    Intersection == URN *and* URL.

    All URNs are URIs.
    All URLs are URIs.

    Some (but not all) URLs are also URNs, and
    some (but not all) URNs are also URLs.

    Some (but not all) URIs are URNs, and
    some (but not all) URIs are URLs, and
    some (but not all) URIs are both URLs and URNs.


Feel free to comment, ask questions if you have any doubt.