URL vs. URI vs. URN, in More Concise Terms

Without a doubt, the URL vs. URI post is by the most visited page on this blog. Even so, there’s still a lot of confusion on the topic and so I thought I’d break it down in less words. The original post was slightly misleading in that I attempted to compare URI to URL, when in fact it should have defined the relationship between URI, URL, and URN. In this post, I hope to clear that in more concise terms. But first, here’s a pretty picture:


Both URLs and URNs are specializations, or subclasses of URI. You can refer to both URLs and URNs as a URI. In applictaion terms: if your application only calls for a URI, you should be free to use either or.
Now, here’s where the big difference between URN and URL: a URL is location bound and dereferencable over the web. A URN is just a name and isn’t bound to a network location. However, BOTH are still valid URIs. Now, if the application requires a URI that is bound to a network location, you must use the specialization of URI called URL.

Remember that URI stands for Uniform Resource Identifier, which is used to identify some “thing”, or resource, on the web. Both URLs and URNs are specialization’s (or subclasses if you will), of URI. You’d be correct by referring to both a URL or URN as a URI. In applictaion terms: if your application only calls for an identifier, you should be free to use either a URL or a URN. For brevity, you can state that the application simply requires a URI and the use of a URL or URN would statisfy that requirement.

Now if your application needs a URI that dereferencable over the web, you should be aware of the difference between URN and URL. A URL is location bound and defines the mechanism as to how to retrieve the resource over the web. A URN is just a name and isn’t bound to a network location. For example, you may have a URN for a books ISBN number in the form of urn:isbn:0451450523. The URN is still a valid URI, but you cannot dereference it, it’s just a name used to provide identity. So to put in simpler terms:

  • A URI is used to define the identity of some thing on the on the web
  • Both URL and URN are URIs
  • A URN only defines a name, it provides no details about how to get the resource over a network.
  • A URL defines how to retrieve the resource over the web.
  • You can get a “thing” via a URL, you can’t get anything with a URN
  • Both URL and URN are URIs as the both identify a resource

There some other items that need clarification based on some comments I’ve received from the original post:

  • Elements of a URI such as query string, file extension, etc. have no bearing on whether or not a URL is a URI. If the URI is defines how to get a resource over the web, it’s a URL.
  • A URL is not limited to HTTP. There are many other protocol schemes that can be plugged into a URL.
  • If a URL defines a scheme other than HTTP, it does not magically become a URI. The URI defines how to get the resource, whether it be HTTP, FTP, SMB, etc., it’s still a URL. But because the URL identifies a resource, it’s a URI as well.

Yeah, I’ve probably repeated myself a few times, but I wanted to stress a few points.

There’s also been some confusion about when to use the term URI. As I stated in the original post explained above, it depends on what you’re doing. If everything your application does involves accessing data over the web, you’re most likely using URL exclusively. In that case, it wouldn’t be a bad thing to use the term URL. Now, if the application can use either a network location, or a name, then URI is the proper term. For example, XML namespaces are usually declared using a URI. The namespace may just be a name, or a URL that references a DTD or XML Schema. So if you’re using a URL for identity and retrieval, it’s probably best to use URI.

Be Sociable, Share!
    • Pingback: DamnHandy » URI vs. URL: What’s the Difference?()

    • Vincent Yin

      Your “class diagram” helps. I have a few questions…
      (1) Is URI sort of an “abstract class” where the only possible concrete forms are URN and URL? In other words, you can never have an example of a URI that is neither URN nor URL, correct?

      (2) I think URN is a logical choice for XML namespaces, yet almost all XMLs use URL. Your post says that a URL for namespace might be reasonable if the XSD is actually located at that URL. I disagree. XSD’s network location, if you wish to express it, is defined by the element xs:include schemaLocation=”http://www.aRealWebsite.com/xxx.xsd”. So, it makes no sense to use URL such as “http://www.fakeDomain.com/fake” as the namespace, although not illegal. When you’re writing a program, you wouldn’t name your variables with senseless names like “myFakeVar1″, “myFakeVar2″, etc. So why give a namespace the value of a fake website?

    • http://buildinschool.wordpress.com/ buildin

      Thats true, XMLS use Url.

    • Pawel

      Very useful, but would be much better if instead of rules you provided more examples.

    • Garygscc

      Thanks for this post. Does this mean that a URI can only ever be a URL or a URN, or are there other URI subsets that you’ve not mentioned?

    • gomathi

      its very well explained Precisely. Thanks

    • http://damnhandy.com Ryan

      There are no other subsets of URI; URN and URL are the only two specializations. Of course, the W3Cs IRI work (Internationalized Resource Identifiers) might be considered a superset of URI.

    • Pingback: Who Goes There? An investigation into XCRI and Identifiers « Culture Campus Liverpool Portal()

    • Pingback: DamnHandy » URL vs. URI vs. URN: The Confusion Continues()

    • Pingback: URL, URI & URN.. cakewalk? Not for me atleast.. | Super Compiler()