URLs and DNS
Anatomy of a URL, domain names, and how DNS resolves them
Skills taught: web.url-anatomy, web.dns, web.domain-names
Anatomy of a URL
Every URL you have ever typed or clicked follows the same structure. Understanding each part helps you construct correct links, debug broken ones, and design clean API routes.
https://api.example.com:443/users/42?format=json&lang=en#profile
│ │ │ │ │ │
│ │ │ │ │ └── Fragment
│ │ │ │ └── Query string
│ │ │ └── Path
│ │ └── Port
│ └── Host (domain)
└── Scheme
Scheme → https (which protocol to use)
Host → api.example.com (which server to talk to)
Port → 443 (which port on the server; 443 is default for HTTPS, usually omitted)
Path → /users/42 (which resource on the server)
Query → format=json&lang=en (key=value pairs, separated by &)
Fragment → profile (browser scrolls to this; NEVER sent to the server)
- Scheme —
http or https. Tells the browser which protocol to use. Always use https — it encrypts the connection. - Host — the domain name. Translated to an IP address by DNS.
- Port — a number from 0–65535. HTTP defaults to
80, HTTPS to 443. Omit when using defaults. - Path — the location of the resource on the server. Like a file path on disk. Starts with
/. - Query string — optional parameters after
?. Keys and values joined by =, pairs joined by &. - Fragment — after
#. The browser uses this to scroll to an element with that ID. Never sent to the server — purely client-side.
Domain names and DNS
DNS (Domain Name System) is the internet's phone book. It translates human-readable domain names like kernal.dhurta.org into IP addresses like 185.199.108.153 that computers use to connect.
Domain: kernal . dhurta . org
│ │ │
│ │ └── TLD (Top-Level Domain): .org, .com, .io, .dev
│ └── Second-level domain: you register this (e.g. on Namecheap, GoDaddy)
└── Subdomain: you configure this in your DNS settings
DNS lookup sequence:
1. Browser cache (remembers recent lookups)
2. OS cache (/etc/hosts on Linux/Mac, C:\Windows\System32\drivers\etc\hosts on Windows)
3. Router cache
4. ISP recursive DNS resolver
5. Root nameservers (13 clusters worldwide, know where .org lives)
6. TLD nameservers (.org knows where dhurta.org nameservers are)
7. Authoritative nameserver for dhurta.org → returns 185.199.108.153
8. Result cached with TTL (time-to-live). Common TTLs: 300s–86400s
Tip: You can look up any domain's DNS records in your terminal: nslookup kernal.dhurta.org or dig kernal.dhurta.org. Browsers also show DNS timing in the Network panel's request waterfall.
Frequently Asked Questions
What is the difference between a URL, a URI, and a URN?
URI (Uniform Resource Identifier) is the broadest term — it identifies a resource. URL (Uniform Resource Locator) is a URI that also specifies how to locate it (http://, ftp://, etc.). URN (Uniform Resource Name) identifies without saying how to find it (like an ISBN for books). In everyday web development, URL is the term you use.
Why does localhost not need DNS?
localhost is a special hostname that always resolves to 127.0.0.1 (IPv4) or ::1 (IPv6) — your own machine. It is defined in the operating system's hosts file, bypassing DNS entirely. This is why your development server is instant — no DNS lookup.
Can a URL have a space in it?
No — spaces and many special characters are not allowed in URLs. They must be percent-encoded: a space becomes %20, a # becomes %23. Browsers handle this automatically when you paste a URL, and the URLSearchParams API handles it when building query strings in JavaScript.