336

What's the difference between an URI, URL and URN? I have read a lot of sites (even Wikipedia) but I don't understand it.

URI: http://www.foo.com/bar.html
URL: http://www.foo.com/bar.html
URN: bar.html

Is this correct?

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
thom
  • 3,371
  • 3
  • 15
  • 4
  • 2
    Worth reading (perhaps after reading the answer provided below): http://www.w3.org/TR/uri-clarification/ Also, the following two links may help clarify when something is a URL VS URN. Permanent URI Schemes: (URL/URN namespaces I guess, though URN has it's own entry in this list which leads to the next link I provide here) http://www.iana.org/assignments/uri-schemes.html URN Namespaces: www.iana.org/assignments/urn-namespaces/urn-namespaces.xml – Lemmings19 Jun 26 '12 at 22:11

4 Answers4

434

A Uniform Resource Identifier (URI) is a string of characters used to identify a name or a resource on the Internet.

A URI identifies a resource either by location, or a name, or both. A URI has two specializations known as URL and URN.

A Uniform Resource Locator (URL) is a subset of the Uniform Resource Identifier (URI) that specifies where an identified resource is available and the mechanism for retrieving it. A URL defines how the resource can be obtained. It does not have to be a HTTP URL (http://), a URL can also start with ftp:// or smb://, specifying the protocol that's used to get the resource.

A Uniform Resource Name (URN) is a Uniform Resource Identifier (URI) that uses the URN scheme, and does not imply availability of the identified resource. Both URNs (names) and URLs (locators) are URIs, and a particular URI may be both a name and a locator at the same time.

This diagram (source) visualizes the relationship between URI, URN, and URL:

URI, URN, URL diagram

The URNs are part of a larger Internet information architecture which is composed of URNs, URCs and URLs.

bar.html is not a URN. A URN is similar to a person's name, while a URL is like a street address. The URN defines something's identity, while the URL provides a location. Essentially URN vs. URL is "what" vs. "where". A URN has to be of this form <URN> ::= "urn:" <NID> ":" <NSS> where <NID> is the Namespace Identifier, and <NSS> is the Namespace Specific String.

To put it differently:

  • A URL is a URI that identifies a resource and also provides the means of locating the resource by describing the way to access it
  • A URL is a URI
  • A URI is not necessarily a URL

I'd say the only thing left to make it 100% clear would be to have an example of an URI that is not an URL. We can use the examples in RFC3986:

URL: ftp://ftp.is.co.za/rfc/rfc1808.txt
URL: http://www.ietf.org/rfc/rfc2396.txt
URL: ldap://[2001:db8::7]/c=GB?objectClass?one
URL: mailto:John.Doe@example.com
URL: news:comp.infosystems.www.servers.unix
URL: telnet://192.0.2.16:80/
URN (not URL): urn:oasis:names:specification:docbook:dtd:xml:4.1.2
URN (not URL): tel:+1-816-555-1212 (disputed, see comments)
Community
  • 1
  • 1
ayush
  • 14,350
  • 11
  • 53
  • 100
  • 92
    Perhaps an example can clarify this: the ISBN number used for books is in fact a **URN**, it's a unambiguous identifier for a given book. But a ISBN number is not a **URL** as it does not define where the book can be found. – Stefan Gehrig Feb 06 '11 at 12:51
  • 28
    `urn:isbn:0-486-27557-4` (a specific edition of Shakespeare's play Romeo and Juliet) is in fact a **URN** (and therefore it's a **URI**), but it's not a **URL**. – Stefan Gehrig Feb 06 '11 at 12:53
  • So, URN are unique? And what about URN's in URI's? Any example? Thank you. – thom Feb 06 '11 at 12:55
  • 17
    By the way: the `tel` example is not a perfect one as one might argue that it is in fact a **URL** (even tough it's not a **URL** in the common internet-influenced area). – Stefan Gehrig Feb 06 '11 at 12:56
  • @thom:as Stefan said "unambiguous" so they do identify there resource uniquely. – ayush Feb 06 '11 at 12:58
  • @thom: Yes, **URNs** are supposed to be unique and to unambiguously identify a given resource (whatever that may be). A **URI** is, and that's what ayush stated above, the set union of **URLs** and **URNs**, the superclass so to speak. – Stefan Gehrig Feb 06 '11 at 12:59
  • @Stefan: it is an URN because even if it identifies a resource it doesn't provide the means to locate it. still even i am unsure. – ayush Feb 06 '11 at 13:00
  • 1
    @thom : check http://www.w3.org/TR/uri-clarification/ for more. – ayush Feb 06 '11 at 13:06
  • 8
    @ayush: A telephone number is in fact the description of the location of a given telephone connection. The number allows the telephone system to locate the receiver in the world-wide telephone network due to its unique telephone number and route the call appropriately (`+1` for the USA, `816` for Missouri, etc.). – Stefan Gehrig Feb 06 '11 at 13:07
  • @Stefan : still you can't pin down the exact location. Like house number. Its only logical say upto city. What after that? – ayush Feb 06 '11 at 13:13
  • @ayush: Sure you can... The telephone company knows exactly where the call will be routed to. But I agree generally I wouldn't consider a telephone number to be a **URL** in the general common sense. – Stefan Gehrig Feb 06 '11 at 13:21
  • But bar.html would be an URN? Thank you. – thom Feb 06 '11 at 13:22
  • no it won't be.A URN is similar to a person's name, while a URL is like a street address. The URN defines something's identity, while the URL provides a location. Essentially, "what" vs. "where".u URN has to be of this from ` ::= "urn:" ":" ` where is the Namespace Identifier, and is the Namespace Specific String. – ayush Feb 06 '11 at 13:36
  • 1
    `tel` can't be an URN as URNs use the URI scheme `urn`, or am I wrong? – unor Dec 15 '12 at 01:28
  • ISBNs are intended to be unique, but in the real world this is not always the case. There is a small percentage of ISBNs which are used on more than one book. – hippietrail Dec 21 '12 at 09:53
  • 1
    What about `javascript:alert(123);`? Is this URI or URL? – Preco Plusb Dec 26 '15 at 22:35
  • 1
    following @unor's comment, it's confusing that you say "An URN has to of the form ` ::= "urn:"...` and then give an example of an URN that's not of that form (`tel:+1-816...`). Does an URN need to begin with `urn:`? – drs Feb 26 '18 at 17:16
  • The statement "and a particular URI may be both a name and a locator at the same time" is misleading: There is no overlap between URNs and URLs. Of course every URL is trivially a name for the location, but not a unique name for a specific resource. – Johannes Overmann Jan 29 '19 at 09:35
  • And the "tel:" example is wrong. It is not a URN. – Johannes Overmann Dec 06 '19 at 16:31
  • ok nice. but what's a URC that you mentioned? – some_groceries Mar 21 '20 at 11:27
  • so an URI can be accessed, by using a URN or by using a URL? – Anish Gopinath Mar 29 '20 at 08:04
  • To Anyone who's watching this: Why can't we see or **get the clear visible & unencoded URN string of any resource** we're randomly browsing, easily on Internet/Web i,e, on Browser/relevant Application, why so **secrecy** and **non-transparency** in that case ? Is it due to security concerns ? Is there any method to know the URN of resource whose owner doesn't wish(or didn't care for) that URN to be known ? – Vicky Dev Jul 26 '22 at 00:32
  • @ayush telephone number can pin the location down to the pocket your cellphone is in, while `https://google.com/example.html` can only pin the location down to "one of Google's (tens? hundreds? thousands?) data centers, somewhere in the world". Either way, the physical location has nothing to do with it - it's the ability to *abstractly* "locate" the thing *through that scheme* that makes something a URL: `https://google.com/example.html` is precise enough to pin down `example.html` at `google.com` through HTTP. `tel:...` is precise enough to pin down that phone in the global phone system. – mtraceur Oct 11 '22 at 05:36
  • The more relevant comparison for `tel:` is URLs like `tcp://`, `udp://` and `sctp://`. The part that follows is an IP address (and a port, but for many purposes that's just two more bytes of a total "address"). If you hit `udp://8.8.8.8:9`, what exactly are you "locating"? Well, a computer(-like thing) which happens to currently have that address and port route to it from you. When you hit `tel:` URwhatever, you are locating a phone(-like thing) which happens to currently have that number route to it from you. Seems rather same to me. – mtraceur Oct 11 '22 at 05:45
  • @VickyDev the thing doesn't necessarily *have* a URN, and it's generally not useful so for example web server software doesn't go out of its way to get/assign/publish URNs for pages or files that it serves. Like, I could make a webpage, but is anyone assigning a URNs for every little HTML page I write? is there an automatic algorithm to give it a URN that is reliably globally unique? Not that I know of. – mtraceur Oct 11 '22 at 05:50
159

Below I sum up Prateek Joshi's awesome explanation.

The theory:

  • URI (uniform resource identifier) identifies a resource (text document, image file, etc)
  • URL (uniform resource locator) is a subset of the URIs that include a network location
  • URN (uniform resource name) is a subset of URIs that include a name within a given space, but no location

That is:

enter image description here

And for an example:

enter image description here

Also, if you haven't already, I suggest reading Roger Pate's answer.

Community
  • 1
  • 1
Gustavo Mori
  • 8,319
  • 3
  • 38
  • 52
  • 9
    Because when using visuals it is much more easier/intuitive to get around. – sitilge Jan 06 '15 at 08:55
  • 11
    what's marked as a URN is not *technically* one, as stated in accepted answer, "A URN has to be of this form ::= "urn:" ":" where is the Namespace Identifier, and is the Namespace Specific String.". though it is sort of a urn functionally hiding underneath the url. – Alex Moore-Niemi May 02 '15 at 23:04
  • 1
    According to this answer, there are URIs which are neither a URL nor a URN. But it looks very strange to me... – floatingpurr Apr 05 '17 at 09:27
  • 1
    @superciccio14, yes, I agree. wanted to point it out either. Can the author of the answer give some examples of the URIs which are neither URLs, nor URNs? – Varvara Kalinina Jun 11 '17 at 11:01
  • 1
    I think this is wrong. There is no overlap between URL and URN. – Johannes Overmann Jan 29 '19 at 09:33
  • @JohannesOvermann I think people get mixed up between the functionality of a URN and the formal URN format. Conceptually a URL names a resource as well as locating it and pragmatically that is how many URLs are used, as names and locators. But nothing other than a string that follows the URN format is a true URN therefore no URLs are true URNs. – CognizantApe Dec 06 '19 at 00:12
101

URL -- Uniform Resource Locator

Contains information about how to fetch a resource from its location. For example:

  • http://example.com/mypage.html
  • ftp://example.com/download.zip
  • mailto:user@example.com
  • file:///home/user/file.txt
  • http://example.com/resource?foo=bar#fragment
  • /other/link.html (A relative URL, only useful in the context of another URL)

URLs always start with a protocol (http) and usually contain information such as the network host name (example.com) and often a document path (/foo/mypage.html). URLs may have query parameters and fragment identifiers.

URN -- Uniform Resource Name

Identifies a resource by name. It always starts with the prefix urn: For example:

  • urn:isbn:0451450523 to identify a book by its ISBN number.
  • urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66 a globally unique identifier
  • urn:publishing:book - An XML namespace that identifies the document as a type of book.

URNs can identify ideas and concepts. They are not restricted to identifying documents. When a URN does represent a document, it can be translated into a URL by a "resolver". The document can then be downloaded from the URL.

URI -- Uniform Resource Identifier

URIs encompasses both URLs, URNs, and other ways to indicate a resource.

An example of a URI that is neither a URL nor a URN would be a data URI such as data:,Hello%20World. It is not a URL or URN because the URI contains the data. It neither names it, nor tells you how to locate it over the network.

There are also uniform resource citations (URCs) that point to meta data about a document rather than to the document itself. An example of a URC would be an indicator for viewing the source code of a web page: view-source:http://example.com/. A URC is another type of URI that is neither URL nor URN.

Frequently Asked Questions

I've heard that I shouldn't say URL anymore, why?

The w3 spec for HTML says that the href of an anchor tag can contain a URI, not just a URL. You should be able to put in a URN such as <a href="urn:isbn:0451450523">. Your browser would then resolve that URN to a URL and download the book for you.

Do any browsers actually know how to fetch documents by URN?

Not that I know of, but modern web browser do implement the data URI scheme.

Can a URI be both a URL and a URN?

Good question. I've seen lots of places on the web that state this is true. I haven't been able to find any examples of something that is both a URL and a URN. I don't see how it is possible because a URN starts with urn: which is not a valid network protocol.

Does the difference between URL and URI have anything to do with whether it is relative or absolute?

No. Both relative and absolute URLs are URLs (and URIs.)

Does the difference between URL and URI have anything to do with whether it has query parameters?

No. Both URLs with and without query parameters are URLs (and URIs.)

Does the difference between URL and URI have anything to do with whether it has a fragment identifier?

No. Both URLs with and without fragment identifiers are URLs (and URIs.)

Is a tel: URI a URL or a URN?

For example tel:1-800-555-5555. It doesn't start with urn: and it has a protocol for reaching a resource over a network. It must be a URL.

But doesn't the w3C now say that URLs and URIs are the same thing?

Yes. The W3C realized that there is a ton of confusion about this. They issued a URI clarification document that says that it is now OK to use URL and URI interchangeably. It is no longer useful to strictly segment URIs into different types such as URL, URN, and URC.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
  • 4
    a `tel:` is a URI because it's an identifier. Read RFC 3966. It's not a URL, because it doesn't help you locate a resource on the web. There is no actual resource to link to, so that'd be impossible. For example, an anchor href URI for `tel:` would instead launch whatever program is used to dial the number. – taco Apr 05 '16 at 09:13
  • 1
    @raiks This answer was submitted well after other answers. The StackOverflow system is not good at identifying good late answers when there are already highly upvoted answers. It also doesn't help that this question is now closed. I put the same answer on the duplicate: [What is the difference between a URI, a URL and a URN?](https://stackoverflow.com/questions/176264/what-is-the-difference-between-a-uri-a-url-and-a-urn) where it has more up votes, but where the two highest answers still have 10 times the score. – Stephen Ostermiller Sep 21 '16 at 17:02
  • 1
    _Your browser would then resolve that URN to a URL and download the book for you._ -- Not necessarily. For example, if I put in an ISBN URN, where should it take me? A place to buy a physical or digital copy of the book? A place to download or read it online? The URN merely identifies a resource. A URL allows you to specify where to locate a resource. A registered URN without a location uses the `urn` scheme while `https://www.google.com/` is a URL that is also a URN (it both identifies and locates the Google Web Search resource). –  Feb 24 '17 at 06:22
  • Your browser would have to have a "resolver" installed for ISBN numbers that would find a URL for the resource. As far as I know, no browsers have taken a stab at implementing resolvers as called for by the RFC. – Stephen Ostermiller Feb 24 '17 at 08:57
  • 3
    @taco not sure why you are saying `tel:` doesn't help you locate the resource. It is clearly telling you the you can reach it through the conventional telephony network using the PSTN system. Same thing as `http:` says you can reach it with the DNS service using the plain text HTTP, `https:` similarly but through TLS, and `mailto:` using SMTP. What happens when you _click_ on it or whether you have software that can handle a call or send an email is completely irrelevant for the semantics of a URL. Maybe the consumer of the `tel:` is an automated calling system which can handle it easily. – jbx Sep 03 '19 at 18:27
  • @jbx because it's an ID, not a file at a location. A URL will point to a file. Are you saying a telephone number is a file you can reach via hypertext? Obviously not. A `tel:` is just an ID; a URI. – taco Sep 17 '19 at 07:55
  • 4
    @taco But why are you saying you have to reach it via hypertext? A URL does not dicate that afaik. `ftp://` and `mailto://` are URLs they are NOT reachable via HTTP. Only `http` URLs are. The ID in a `tel:` URL is the telephone number, and saying it is a `tel:` not only qualifies it but also specifies how to reach it (by calling it via PSTN). Can't see the difference between a `tel:` URL and for example a `sip:` URL. Even Microsoft refers to them as URLs: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms776001(v=vs.85) – jbx Sep 17 '19 at 08:32
  • @StephenOstermiller Data URI are now called Data URL. Source : [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs). So can we now say URI is either URN or URL ? – Number945 Mar 23 '20 at 13:40
  • 1
    @Number945 That is consistent with the [URI clarification document](http://www.w3.org/TR/uri-clarification/) that *any* URI can now be called a URL. See [this venn diagram](https://i.stack.imgur.com/FbaKm.png) – Stephen Ostermiller Mar 23 '20 at 13:52
3

URI (Uniform Resource Identifier) according to Wikipedia:

a string of characters used to identify a resource.

URL (Uniform Resource Locator) is a URI that implies an interaction mechanism with resource. for example https://www.google.com specifies the use of HTTP as the interaction mechanism. Not all URIs need to convey interaction-specific information.

URN (Uniform Resource Name) is a specific form of URI that has urn as it's scheme. For more information about the general form of a URI refer to https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax

IRI (International Resource Identifier) is a revision to the definition of URI that allows us to use international characters in URIs.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
gst
  • 828
  • 5
  • 15