5 / 6 · Basic
DNS: turning names into addresses
The 13 root name servers are run by 12 organisations from 2047 machines around the world (root-servers.org, 17 October 2026).
Jump to the 10 practice questionsYou will learn
- Read a domain name as a path down a tree
- Follow a lookup from resolver to authoritative server
- Use TTL to tell when a cached answer is reused
Before this: TCP, UDP and ports
1Explain
One file for the whole network
Before DNS, every computer on the ARPANET kept a copy of one text file, HOSTS.TXT, listing every host name and address. The Stanford Research Institute's Network Information Center maintained it, and every site downloaded fresh copies. As the network grew, the file grew, changes took longer to spread, and names clashed. RFC 1034 describes this problem and the design that replaced it: a tree of names, each part looked after by its own servers. DNS was published as RFC 1034 and RFC 1035 in 1987.
2Problem
What DNS replaced
What did DNS replace?
Hint
A single text file.
Solution
Answer: One HOSTS.TXT file copied to every computer
DNS spread the job across a tree of servers instead of one shared file.
3Explain
The phonebook of the internet
Nobody downloads that file now. You type example.com rather than 198.51.100.20, and the name is looked up at the moment you need it. Routers still only understand numbers, though, so before your browser can send a single packet to a website, the name has to become an address. The Domain Name System (DNS) does that, and Cloudflare's guide calls it the phonebook of the internet.
4Explain
A name is a path down a tree
Read www.example.com from the right. At the top is the root, written as an invisible dot. Below it are top-level domains (TLDs) such as com, org and kr. Below com is example, and below that is www. Each piece is a label; RFC 1035 allows up to 63 bytes per label and 255 bytes for a whole name. Different organisations run different branches of the tree, so no single computer has to know every name. That was exactly what went wrong with HOSTS.TXT, where one file on every machine tried to hold them all.
The DNS tree. www.example.com is the path www → example → com → root, read from left to right but looked up from the root down.
5Explore
Labels from the right
Reversed, the labels read from the top-level domain down to the host, the order a lookup takes from the root.
const name = "www.example.com";
const labels = name.split(".");
console.log(labels.reverse().join(" → "));
console.log(labels.length);com → example → www
36Problem
The longest label
What is the longest a single label (such as example) may be under RFC 1035?
bytes
Hint
RFC 1035 sets it in bytes.
Solution
Answer: 63 bytes
Labels are 63 octets or less; a whole name is 255 or less.
7Explore
Four servers, eight steps
Cloudflare lists four kinds of server in a lookup. The recursive resolver, usually run by your ISP or a public DNS service, does the legwork for you. A root server knows where the TLD servers are. A TLD server, such as the one for com, knows which servers hold each domain beneath it. The authoritative server for a domain holds its actual records and gives the final answer. With nothing cached, a lookup takes eight steps. Your computer asks the resolver.
Drag to turn. Scroll or pinch to zoom.
8Problem
Who the resolver asks
An uncached lookup of www.example.com: which servers does the resolver ask, in order?
- Root server
- example.com authoritative server
- com TLD server
Hint
From the top of the tree down.
Solution
Answer:
- Root server
- com TLD server
- example.com authoritative server
Root → TLD → authoritative: each one points to the next until the last one answers.
9Problem
The final answer
Which server gives the final answer for www.example.com?
Hint
The server that holds the records of the domain.
Solution
Answer: The authoritative server for example.com
Root and TLD servers only refer the resolver onward.
10Problem
Steps without a cache
How many steps does an uncached lookup take in Cloudflare's description?
steps
Hint
Count the arrows in the simulator.
Solution
Answer: 8 steps
Four questions and four answers: computer ↔ resolver, resolver ↔ root, ↔ TLD, ↔ authoritative.
11Explain
Why the second lookup is instant
If every lookup took eight steps, DNS would be slow and the root servers would drown in questions. So answers are kept. They are cached in the browser, in the operating system and in the resolver. Each record comes with a time to live in seconds, set by the domain owner. A TTL of 3600 means "you may reuse this answer for an hour". A short TTL lets an owner move a site quickly; a long one saves lookups.
12Problem
TTL 3600
A record has TTL 3600. For how many minutes may a cache reuse it?
minutes
Hint
3600 seconds in minutes.
Solution
Answer: 60 minutes
TTL is in seconds: 3600 ÷ 60 = 60 minutes.
13Problem
Asked again after 10 seconds
You looked up a name 10 seconds ago and the browser cache keeps it for 60 seconds. How many DNS messages leave your computer if you look it up again now?
messages
Hint
The browser still has it.
Solution
Answer: 0 messages
The browser cache answers; nothing is sent.
14Problem
Root server names
How many named root servers are there?
Hint
Letters a to m.
Solution
Answer: 13
a to m: 13 names, run by 12 organisations as many copies.
15Explain
Two kinds of question, one port
One lookup mixes two kinds of question. Your computer sends the resolver a recursive query, which means "give me the final answer or an error". The resolver then sends iterative queries to the root, TLD and authoritative servers, and each replies with the best it has, often only a pointer to the next server. DNS messages go to port 53, normally over UDP because a question and an answer each fit in one packet. Large answers and transfers between servers use TCP, which RFC 7766 makes a required part of every full DNS implementation.
16Explain
Records hold more than addresses
| Record | Holds | Example |
|---|---|---|
| A | An IPv4 address | www.example.com → 198.51.100.20 |
| AAAA | An IPv6 address (RFC 3596) | www.example.com → 2001:db8::20 |
| CNAME | Another name to look up instead | shop.example.com → example.com |
| MX | The mail server for the domain | example.com → mail.example.com |
| NS | The authoritative name servers | example.com → ns1.example.com |
17Problem
An IPv6 address
Which record holds an IPv6 address?
Hint
Four times the letter A.
Solution
Answer: AAAA
A holds IPv4, AAAA holds IPv6 (RFC 3596).
18Problem
MX
What is an MX record for?
Hint
Mail eXchange.
Solution
Answer: Naming the mail server for a domain
Mail servers look up MX records to know where to deliver mail for a domain.
19Practice
A cache with a TTL
A name is looked up at the given seconds. Finish sent(times, ttl): count the lookups that must go to the network, because nothing is cached yet or the cached answer is ttl seconds old or older. A lookup that goes out is cached again.
2
2
3function sent(times, ttl) {
let count = 0, cachedAt = null;
for (const t of times) {
count++;
}
return count;
}
console.log(sent([0, 10, 3000, 4000], 3600));
console.log(sent([0, 30, 60], 60));
console.log(sent([0, 100, 200], 0));
Hint
Remember when the answer was cached, and send again once ttl seconds have passed.
A solution
function sent(times, ttl) {
let count = 0, cachedAt = null;
for (const t of times) {
if (cachedAt === null || t - cachedAt >= ttl) {
count++;
cachedAt = t;
}
}
return count;
}
console.log(sent([0, 10, 3000, 4000], 3600));
console.log(sent([0, 30, 60], 60));
console.log(sent([0, 100, 200], 0));20Explain
Common mistakes
"DNS stores the web pages."
DNS only answers with records such as addresses, mail servers and other names. The page itself comes from the web server at the address DNS returned.
"When a site changes its address, everyone sees the new one at once."
Browsers, operating systems and resolvers keep the old answer until its TTL runs out. With a TTL of 3600, some visitors can still be sent to the old address for up to an hour.
"There are exactly 13 root server computers."
There are 13 names, a to m, run by 12 organisations. On 17 October 2026 they were answering from 2047 instances around the world.
"My computer asks the root server itself."
Your computer asks the recursive resolver once. The resolver walks from the root to the TLD server to the authoritative server and hands back only the result.
21
Summary
- DNS turns names into addresses; names are read right to left down a tree.
- Recursive resolver → root → TLD → authoritative: eight steps with nothing cached.
- Answers are cached in the browser, OS and resolver for the record's TTL (seconds).
- A = IPv4, AAAA = IPv6, CNAME = alias, MX = mail, NS = name servers.