Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Networking

How does DNS work?

You type a name, a number comes back. Here is the chain of small servers behind it, and why DNS changes take time.

Derpx0627 Oct · 4 min read
Contents
Why not just one giant list?Which servers take part?What happens when I type a name?Why is it fast then?So why do "DNS changes take time"?Can I watch this on my own laptop?What to learn nextSources
0% read · 4 min leftBack to top ↑
On this page0%
Contents
Why not just one giant list?Which servers take part?What happens when I type a name?Why is it fast then?So why do "DNS changes take time"?Can I watch this on my own laptop?What to learn nextSources

You type a website name and the page appears. But computers cannot use names. They only use numbers.

So something has to turn example.com into an address like 93.184.216.34 before anything loads. That something is DNS, the Domain Name System. The key idea: nobody holds the whole answer. DNS is a chain of small servers, and each one only knows who to ask next.

Think of it like this

You want to find one apartment in a big city. The city office knows which district. The district office knows the street. The street sign shows the building. Nobody knows everything, but each one knows where to send you next.

Why not just one giant list?

One list means one huge target and one huge bottleneck. RFC 1034, the original design document, wanted the data spread out and cached close to the people asking. So the work got split up.

The split follows the name itself. You read a domain from right to left, like a postal address that goes country, city, street.

Root (the dot at the very end)
TLD (.com, .in, .org)
Domain (example)
Host (www)
Reading www.example.com from the bottom up. Each layer hands you to the next.

So who actually answers at each layer? Meet the cast.

Which servers take part?

Four kinds of servers take part in a lookup.

ServerJobLike
Recursive resolverDoes the whole hunt for you and remembers answersA helper who does the whole search for you
Root serverKnows who handles each TLD like .comThe city information desk
TLD serverKnows who handles each domain under that TLDThe district office
Authoritative serverHolds the real answer for the domainThe official address book

The root has 13 server identities (A to M), run by 12 organisations according to root-servers.org. Each identity is really many machines around the world, but you don't need that yet.

Now let's see them work together.

What happens when I type a name?

Your phone doesn't do the hunt. It asks the recursive resolver, usually run by your ISP or something like 1.1.1.1 or 8.8.8.8. The resolver does the legwork.

Click Next and follow the question from your phone to the authoritative server and back.

Your phone
Resolver
Root
TLD
Authoritative

Phone asks the resolver for the IP of example.com

Step 1 of 7
One lookup, hop by hop. Root and TLD only point, the authoritative server answers.

Root and TLD never give the final answer. They only point to the next server. RFC 1034 calls this a referral. Doing the whole hunt for you is the optional part, called recursive service.

So that's six or seven hops for every single website. Why doesn't that feel slow?

Why is it fast then?

Caching. A cache is a saved copy, so you don't redo the work. RFC 1034 gives a main goal of the resolver is to cut network delay and server load by answering from its saved copies.

The first lookup takes time. When the same name is asked again, the resolver already has the answer.

TTL (Time To Live)

A number in each DNS record, in seconds, that tells resolvers how long they may keep a saved copy before asking again. RFC 1035 defines it as a 32 bit value. Zero means don't cache it.

Caching is great, until the answer changes.

So why do "DNS changes take time"?

Say you move your site to a new server and change its IP at the authoritative server. That change is instant there. But resolvers around the world still hold the old answer until its TTL runs out.

Right after the changeYou changed the IP. Some resolvers still hold the old one until its TTL expires.
→
After the TTL passesEach cached copy expires and gets refreshed. Now everyone sees the new IP.

Some resolvers have the new answer and some still hold the old one. Nobody is wrong. They just have different copies.

The practical trick: lower the TTL before a planned move so old copies die quickly, then raise it again after.

Can I watch this on my own laptop?

Yes. dig is a small tool that asks DNS questions. It comes on most Linux and Mac setups, and in a package like dnsutils or bind-utils if you don't have it.

Bash
dig +trace example.com

The +trace flag makes dig do the hunt itself, starting at the root, so you see the same walk as the Stepper above. (Your output will differ, so run it and read the hops yourself.)

Now run plain dig example.com twice. The number in the answer line before the record type is the TTL. It counts down when a resolver serves you a cached copy.

What to learn next

  • Record types: A and AAAA (addresses), CNAME (alias), MX (mail), NS (who's in charge).
  • Why DNS mostly uses UDP and small messages (RFC 1035 mentions a 512 byte limit for the basic version).
  • DNS over HTTPS, which hides your lookups from others on the same network.
Key takeaways
  • DNS is a chain of small servers, each one only knowing who to ask next.
  • A lookup goes resolver, root, TLD, authoritative, and each step is a pointer to the next.
  • Caching makes it fast, and the TTL sets how long a saved copy lives.
  • "DNS changes take time" really means old cached copies are waiting for their TTL to run out.

Sources

  • RFC 1034: Domain Names, Concepts and Facilities
  • RFC 1035: Domain Names, Implementation and Specification
  • Root Servers (root-servers.org)
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Networking · 4 minHow does HTTPS work? What the padlock really doesFoundations · 3 minWhy is 0.1 + 0.2 not 0.3 in code?Foundations · 4 minHow does Git work inside? (Snapshots, not changes)
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)