Comparing URI vs URL
All URLs can be considered URIs, but not all URIs can be regarded as URLs. Confusing, isn't it? Read this article for clarity.
The URL full form, which is Uniform Resource Locator, is a widely used term across the Internet to define a particular web address. However, there are other terms that can sometimes be used more appropriately when referencing an online resource. This article aims to identify these terms as well as provide examples regarding when you should use URI vs URL given the particular scenario.
Explanation of a URI
A URI, which stands for Uniform Resource Identifier, should be first understood before explaining what a URL is. According to RFC 3986,
A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource.
A URI can identify a web resource (e.g. an image, video, CSS file, etc.) by location, name, or both. What is meant by "location" is the access mechanism used to retrieve a particular resource, for example, http://
, ftp://
,etc. Additionally, "name" refers to the globally unique name of the resource. For example, given the following web address: https://foobar/path/to/image.jpg
, the foobar/path/to/image.jpg
section of the address refers to the name or URN.
The following sections will explain what defines a URL or URN. However, remember that a URI can encompass either a URL, a URN, or both.
Explanation of URL full form
As mentioned above, the URL full form stands for Uniform Resource Locator, a subset of URIs that identify the network location of a resource. This is achieved by defining a protocol for the web resource. The physical location can be retrieved by describing the network location or primary access mechanism. A URL will therefore contain http://
or https://
at the beginning if the resource is of type "Web". Similarly, a URL begins with ftp://
if the resource is a file.
A URL specifies where the resource can be accessed, unlike a URN, which simply defines the resource's name. A URL would correspond to a person's home address in a real-world example.
When comparing URI and URL, we can see that all URLs can be considered URIs, but not all URIs can be considered URLs. So the URL refers to a subset of the URIs.
For illustration:
keycdn.com
Represents a URI, because it shows us only the name of a resource, while
https://www.keycdn.com
Represents a URL because it is both the name of a resource (keycdn.com) and the path to it (https://).
Explanation of a URN
A URN stands for Universal Resource Name, which is used to identify a resource by a unique name. The downfall of a URN is that it does not provide a location to retrieve a particular web resource. A URN uses a namespace and a namespace identifier to identify the resource in question. According to W3 URI Clarification, a URN namespace comes in the form of urn:isbn:n-nn-nnnnnn-n
, where isbn would be the namespace identifier. In this case, the URN would need to be translated into a URL by a resolver where the document would be subsequently downloaded from a web server.
URNs can also be used to identify documents, such as a book that can be uniquely identified by its ISBN.
Examples
The following examples are all considered URIs as both URLs a URNs fall under the umbrella of URI. However, the following list contains a few examples of resources that can also be considered a URL or URN solely.
mailto:john.doe@example.com
(URL due to themailto:
protocol)http://www.ietf.org/rfc/rfc2396.txt
(URL due to thehttp://
protocol)urn:ietf:rfc:2648
(URN as it does not specify a locator)urn:isbn:0508672084
(URN as it does not specify a locator)
When to use the term URI vs URL
The two terms are closely related, which is why they are often used interchangeably.
There is a fair bit of discussion regarding when and how you should properly use the term URI vs URL. No matter how the URL is structured, it will always be technically correct if you use the term URI. This is because, as mentioned above, a URI can identify a resource by location (URL), name (URN), or both. Therefore it is all-encompassing. URLs are a subset of URIs. This means that all URLs are therefore also URIs. The opposite, on the other hand, is not valid.
However, due to the URI's versatility, some argue that using the term "URL" or the URL full form (Uniform Resource Locator) is a more appropriate choice when the resource contains a specific location identifier. Therefore, if the resource contains a protocol such as http://
, ftp://
, and so on, the term URL is often used as it is more specific. Alternatively, if the resource is less specific in terms of containing a location identifier, then the term URI should be used.