How DNS Actually Works

Fractional CTO · Founder of Injuria.ai
Before your browser can load a single byte of a website, it has to answer a question: what number do I connect to?[6] People use names like example.com, but machines route traffic to IP addresses. The system that translates between the two is DNS, the Domain Name System, and it handles this for every name on the internet, an enormous number of times every second, without any single computer being in charge.[1] It is worth understanding because when it breaks, everything looks broken, and the fix is usually simple once you know the shape of the thing.
The problem it solves
Humans are good at names and bad at numbers. Machines are the opposite. You could keep a giant file mapping every name to every address, and the early internet did exactly that, a shared HOSTS.TXT file maintained at a single institute.[7] That stopped working almost immediately, because the list grew too fast and everyone had to agree on one copy. DNS replaced the single list with a hierarchy that spreads responsibility across millions of servers and leans heavily on caching.[1]
A hierarchy you read right to left
A domain name is a path through a tree, and you read it from the right. Take www.example.com, which technically ends in an invisible trailing dot, www.example.com.. That final dot marks the root of the tree, the empty label at the top of the hierarchy. To its left is the top-level domain, com, then example, and www is a name within that.[2]
Each level is responsible only for delegating the level below it.[8] The root knows where to find the servers for com. The com servers know where to find the servers for example.com. The example.com servers know the actual address of www. No server has to know everything. Each one only has to know who to ask next, and that single idea is what lets the system scale without a central authority.
Who actually answers
Three kinds of authoritative servers form that hierarchy. The root servers sit at the top and point toward the right top-level-domain servers. The top-level-domain servers, for com, org, io, and the rest, point toward the servers responsible for a specific domain. The authoritative servers for a domain hold the real records. There are 13 root server identities, each with an IPv4 and an IPv6 address, which sounds dangerously few until you learn the trick: each one is actually hundreds of machines spread worldwide sharing a single IPv4 and IPv6 address through a routing technique called anycast, so your query reaches a nearby copy rather than one distant box. That is a large part of why the root has never gone down.
Doing the walking is a separate job, handled by a recursive resolver, usually run by your internet provider or a public one like 1.1.1.1 or 8.8.8.8. Your device asks the resolver a simple question and expects a final answer. The resolver does the legwork.[3]
A lookup, step by step
Say your resolver has nothing cached and needs www.example.com from scratch.[6]
your device -> resolver: what is www.example.com?
resolver -> root: who handles .com?
root -> resolver: ask the .com servers (here they are)
resolver -> .com: who handles example.com?
.com -> resolver: ask example.com's servers (here they are)
resolver -> example.com: what is www?
example.com -> resolver: an address
resolver -> your device: an address
That full walk looks like a lot of back and forth, and it is, which is why it almost never happens. Most of the time the resolver already has the answer cached and replies in a millisecond.
The records themselves
A domain is configured with a set of records, each a type for a purpose.[2] An A record maps a name to an IPv4 address and an AAAA record to an IPv6 address. A CNAME is an alias, pointing one name at another name, which is how www.example.com often points at a provider's hostname. An MX record says which servers receive email. A TXT record holds arbitrary text, used for verifying ownership and email authentication. An NS record names the authoritative servers for the domain, which is the delegation itself.[8]
Caching, the TTL, and the thing people call propagation
Every record carries a time to live, a TTL in seconds. When a resolver gets an answer, it keeps it that long before asking again. TTLs are why DNS scales: the root and top-level servers would collapse instantly if every lookup went all the way up the tree, but caching means the vast majority of questions are answered close to the user.
This is also the source of the thing people call propagation. When you change a record, the new value is live at the authoritative server right away, but resolvers around the world keep serving the old cached value until its TTL expires. There is no global push. Everyone is just waiting out their caches. The practical trick before a planned change is to lower the TTL a day ahead of time, so the window of stale answers afterward is short.
A privacy wrinkle worth knowing
For most of its history, DNS traveled in the clear, which means your internet provider, and anyone on the path, could see every name you looked up even on HTTPS sites. That is changing. DNS over HTTPS and DNS over TLS wrap the lookup in encryption, so the questions themselves are private.[4] It is a genuine privacy improvement and a mild operational headache, because it moves resolution out of the network's view and into the browser or the application, which is exactly the kind of tradeoff that makes infrastructure interesting.
Why it rarely breaks, and when it does
DNS is robust because it is both cached and redundant, with multiple servers in multiple places at every level, so the failure of any one is invisible. When something does go wrong, the cause is usually human: a record points at the wrong place, a TTL set to a day means a fix takes a day to take hold, or a delegation was never updated after a move. Because so much depends on it, a small DNS mistake can take down services that are otherwise perfectly healthy, which is why "it was DNS" is an engineering punchline with a hard truth inside it.
The tired description of DNS is a phone book. A better one is a chain of delegation, where no one holds the whole directory and each server knows only who to ask next. It has scaled from a few hundred computers to the entire internet without changing its fundamental shape, and the lesson I take from it is that the most durable systems are the ones that refuse to put anyone in charge of everything.
Sources (8)
- RFC 1034: Domain Names, Concepts and Facilities
- RFC 1035: Domain Names, Implementation and Specification
- MDN Web Docs: DNS
- RFC 8484: DNS Queries over HTTPS (DoH)
- Root Server Technical Operations (root-servers.org)
- Joe Baron, Hisham Baz, Tim Bixler, AWS Certified Solutions Architect Official Study Guide (John Wiley & Sons, 2016)
- Daniel López Ridruejo, Daniel Lopez, Sams Teach Yourself Apache 2 in 24 Hours (Sams Publishing, 2002)
- CP Books a.s., DNS in Action (Packt Publishing Ltd, 2006)