DEV Community

Cover image for Understanding URLs, URIs, and URNs: A Beginner’s Guide to Web Identifiers
Maksym
Maksym

Posted on

Understanding URLs, URIs, and URNs: A Beginner’s Guide to Web Identifiers

The relationship between URLs, URIs, and URNs can be understood through a hierarchical structure where URI is the parent concept, and URLs and URNs are specific types of URIs.

The Hierarchy

URI (Uniform Resource Identifier)
├── URL (Uniform Resource Locator)
└── URN (Uniform Resource Name)
Enter fullscreen mode Exit fullscreen mode

Definitions & Purposes

URI (Uniform Resource Identifier)

  • Broadest category - identifies a resource
  • Purpose: Provides a way to identify resources on the internet
  • Includes: Both URLs and URNs
  • Analogy: Like saying "identifier" - it could be a name, address, or both

URL (Uniform Resource Locator)

  • Subset of URI - identifies AND locates a resource
  • Purpose: Tells you both what the resource is AND how to find it
  • Analogy: Like a home address - tells you where something is located

URN (Uniform Resource Name)

  • Subset of URI - identifies a resource by name
  • Purpose: Provides a persistent, location-independent identifier
  • Analogy: Like a person's name - identifies them regardless of where they live

Examples

URLs (Location-based identifiers)

https://www.example.com/page.html
ftp://files.example.com/document.pdf
mailto:user@example.com
tel:+1-555-123-4567
Enter fullscreen mode Exit fullscreen mode

URNs (Name-based identifiers)

urn:isbn:9780134685991          (Book ISBN)
urn:uuid:12345678-1234-5678-9012-123456789012
urn:ietf:rfc:3986               (IETF RFC document)
urn:doi:10.1000/182             (Digital Object Identifier)
Enter fullscreen mode Exit fullscreen mode

URIs (Could be either)

https://example.com/page.html    (This is a URL)
urn:isbn:9780134685991          (This is a URN)
mailto:john@example.com         (This is a URL)
Enter fullscreen mode Exit fullscreen mode

Key Differences

Aspect URL URN URI
What it does Locates resource Names resource Identifies resource
Location dependent Yes No Depends on type
Changes when moved Yes No Depends on type
Includes access method Yes No Sometimes
Persistent No Yes Depends on type

Real-World Analogy

Think of a book:

  • URI: "Some way to identify the book"
  • URL: "The book is on shelf 3, row 2, position 5 at Downtown Library"
    • Tells you exactly where to find it
    • Changes if the book moves
  • URN: "ISBN 978-0134685991"
    • Identifies the book uniquely forever
    • Doesn't change regardless of location

Practical Implications

URLs are most common

// These are all URLs (they tell you HOW to access the resource)
fetch('https://api.example.com/users')
window.location = 'https://example.com/login'
<img src="https://cdn.example.com/image.jpg" />
Enter fullscreen mode Exit fullscreen mode

URNs are used for permanent identification

<!-- Academic citations -->
<citation doi="urn:doi:10.1000/182" />

<!-- Book references -->
<book isbn="urn:isbn:9780134685991" />

<!-- Unique document IDs -->
<document id="urn:uuid:550e8400-e29b-41d4-a716-446655440000" />
Enter fullscreen mode Exit fullscreen mode

URI is the generic term

def process_resource(uri):
    """
    This function accepts any URI - could be URL or URN
    """
    if uri.startswith('http'):
        # It's a URL - fetch from web
        return fetch_from_web(uri)
    elif uri.startswith('urn:'):
        # It's a URN - resolve through naming service
        return resolve_urn(uri)
Enter fullscreen mode Exit fullscreen mode

Common Misconceptions

Wrong: "URI and URL are the same thing"

✅ Correct: URL is a specific type of URI

Wrong: "All web addresses are URIs"

✅ Correct: All web addresses are URLs, which are a type of URI

Wrong: "URNs aren't used on the web"

✅ Correct: URNs are used for persistent identification (DOIs, ISBNs, etc.)

Technical Specification

According to RFC 3986, a URI has this structure:

scheme:[//authority]path[?query][#fragment]
Enter fullscreen mode Exit fullscreen mode

URL Example:

https://user:pass@example.com:8080/path?query=value#section
  ↑      ↑    ↑    ↑         ↑    ↑     ↑           ↑
scheme  user pass  host    port  path  query    fragment
Enter fullscreen mode Exit fullscreen mode

URN Example:

urn:namespace:specific-string
 ↑      ↑          ↑
scheme namespace  identifier
Enter fullscreen mode Exit fullscreen mode

When to Use Each

Use URL when:

  • You need to access/retrieve a resource
  • Location matters
  • Building web applications
  • Creating hyperlinks

Use URN when:

  • You need permanent identification
  • Location independence is important
  • Academic/scientific references
  • Digital asset management

Use URI when:

  • Speaking generically about identifiers
  • Building systems that handle both URLs and URNs
  • Writing specifications or documentation

Summary

URI is the umbrella term for all resource identifiers on the web. URLs tell you where to find something and how to get it, while URNs give things permanent names that don't change. In everyday web development, you're mostly working with URLs, but understanding this hierarchy helps you choose the right tool for the right job.

Top comments (0)