CMD Guide
HomeSystem DesignAPI Gateway

URL vs URI vs URN

A URI is just a text string that a parser splits into a scheme plus scheme-specific parts; whether that string also tells a machine how to fetch the bytes (a URL) or only names the resource permanently (a URN) depends entirely on whether the scheme carries a resolvable location. URI is the syntactic superset; URL and URN are two roles a URI can play.

The mental hook: a URL answers How (protocol) and Where (location). A URN answers only What (a persistent name). A URI is the umbrella that covers both.

diagram
diagram

Worked example: parsing a real URL (RFC 3986)

Take a fully loaded URL and run the generic-syntax split. Every URI decomposes as scheme ":" ["//" authority] path ["?" query] ["#" fragment], and the authority further splits into [userinfo "@"] host [":" port]. Trace it component by component:

https://ada@shop.example.com:8443/products/42?ref=email&sort=price#reviews
#ComponentValueWhat it does
1schemehttpsThe access mechanism (the How). This is what makes it a URL, not merely a name.
2userinfoadaOptional credentials in the authority. Rarely used, often stripped by clients.
3hostshop.example.comThe Where — resolved to an IP via DNS.
4port8443TCP port; if omitted, defaults per scheme (443 for https).
5path/products/42Hierarchical locator within the host.
6queryref=email&sort=priceNon-hierarchical parameters, sent to the server.
7fragmentreviewsClient-side anchor. Never transmitted in the HTTP request.

Now parse the URN urn:isbn:0451450523: scheme urn, namespace identifier (NID) isbn, namespace-specific string (NSS) 0451450523. There is no host, no port, no path — nothing tells a machine where the book lives. It is a name, not an address. To turn it into bytes you must hand it to a resolver that maps the name to a current location.

diagram
diagram

Pitfalls

Two parsers, one string

The WHATWG/RFC divergence mentioned above is not academic — here is one string parsed two ways:

https://good.example\@evil.example/

A WHATWG-conformant browser treats backslashes in special-scheme URLs as forward slashes, so the authority ends at the backslash: host = good.example, path = /@evil.example/. A strict RFC 3986 split never treats \ as a delimiter, so a library following that grammar reads the authority as good.example\@evil.example and — splitting userinfo at the @ — lands on host = evil.example. Same string, two different hosts. That is why you must never validate a URL with one parser and fetch with another: parser disagreement is an allowlist-bypass/SSRF primitive — the validator approves the host it sees, the fetcher connects to the other one. [VERIFY this example against the current WHATWG URL Standard and one real library (e.g. new URL() in a browser vs a strict RFC-3986 parser) before relying on the exact split.]

When to use a URN vs a URL as your identifier

This is a real design decision the moment you store references to resources (in a database, an API payload, an event, a citation). The choice is identity coupled to location (URL) versus identity decoupled from location, resolved on demand (URN or an opaque persistent ID).

SignalReach for a URN / opaque persistent IDReach for a URL
LifetimeMust stay valid for years/decades regardless of hosting changes (ISBN, DOI, media asset IDs)Short-lived or the location genuinely is the identity
MigrationThe resource will move hosts, CDNs, or storage tiersThe host is stable and owned by you
Client needsClients tolerate a resolver hop to get the current locationClients must fetch bytes directly with zero indirection
CitationThird parties will reference it and must not suffer link rotOnly your own system dereferences it

The trade-off. A URL is the cheapest possible identifier — one string, dereference it directly, no infrastructure. Its cost is link rot: identity is welded to location, so moving the resource invalidates every stored reference. A URN (or an opaque UUID/slug in your own namespace) buys location independence — you can move the bytes anywhere and only update the resolver mapping — but you pay for it with a resolver: extra infrastructure, an extra network hop of latency on every fetch, and a mapping table that must itself never be lost.

Choose a URN/persistent ID when the reference outlives the location and link rot is unacceptable (digital libraries, scientific citation, long-term media catalogs, cross-service entity IDs). Prefer a URL when you own the host, the resource is not expected to migrate, and the simplicity of direct dereferencing outweighs future flexibility. Many mature APIs split the difference: expose a stable opaque ID as the resource's identity and also return a self URL (HATEOAS-style) so clients get persistence and convenience at once.

Takeaways


Re-authored/Deepened for this guide. Sources: RFC 3986 (Uniform Resource Identifier: Generic Syntax, Berners-Lee et al.), RFC 8141 (Uniform Resource Names), the WHATWG URL Living Standard, and MDN Web Docs on URI/URL structure. Worked example and diagrams hand-authored.

🤖 Don't fully get this? Learn it with Claude

Stuck on URL vs URI vs URN? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **URL vs URI vs URN** (System Design) and want to truly understand it. Explain URL vs URI vs URN from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **URL vs URI vs URN** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **URL vs URI vs URN** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **URL vs URI vs URN** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes