A DNS server resolves a domain name by checking its cache, then asking a root server which top-level domain server to use, asking that server which authoritative server holds the domain, and asking the authoritative server for the final IP address. The recursive resolver does this work on your behalf, caches the answer for its time-to-live, and returns the IP address to your browser.
Key takeaways
- A DNS lookup is a chain: stub resolver, recursive resolver, root, TLD and authoritative server — each step narrows the search.
- Most lookups end in a cache, which is why repeat visits are fast; the full walk only happens on a cold lookup.
- Recursive queries ask one server to do the whole job, while iterative queries return referrals that the resolver must follow itself.
You type a domain name, and a website appears. Behind that simple moment is a short chain of questions between servers, each one narrowing the search until a single IP address comes back. This guide follows that chain step by step.
It is written for anyone who runs a website, manages a network, or simply wants to understand why a site sometimes fails to load. You do not need to know any commands to follow it, though we include a few you can try at the end.
How does a DNS server resolve a domain name?
A DNS server resolves a domain name by checking its cache, then walking the DNS hierarchy: it asks a root server for the top-level domain server, asks that server for the authoritative server, and asks the authoritative server for the final IP address. The answer is then cached and returned to your browser.
The Domain Name System is the phonebook of the internet, as Cloudflare explains: humans use domain names such as example.com, while browsers need IP addresses such as 93.184.216.34. DNS translates one into the other.
No single server knows every name. DNS is a distributed, hierarchical database, defined in RFC 1034 and RFC 1035. Each server knows its own zone and points to the next server down the tree.
What are the four DNS servers in a lookup?
Four roles take part in a typical lookup: the stub resolver on your device, the recursive resolver, the root server, the TLD server, and the authoritative server. Cloudflare counts the recursor, root, TLD and authoritative servers as the four server roles, with your device as the client.
The stub resolver lives in your operating system. It does not resolve names itself; it forwards your query to the recursive resolver your network is configured to use, usually from your ISP or a public service such as 8.8.8.8 or 1.1.1.1.
The recursive resolver does the real work. It accepts your query, checks its cache, and walks the hierarchy on your behalf until it has an answer or an error. The root server points it to the TLD, the TLD points it to the authoritative server, and the authoritative server gives the final answer.
What are the eight steps in a DNS lookup?
Cloudflare describes eight steps for a cold lookup of example.com, when nothing is cached. Most real lookups skip most of these steps because the answer is already in a cache somewhere along the chain.
- You type example.com and the query goes to a DNS recursive resolver.
- The resolver queries a root nameserver for the root zone.
- The root responds with the address of the .com TLD server.
- The resolver queries the .com TLD server.
- The TLD responds with the IP address of the nameserver for example.com.
- The resolver queries that nameserver, the authoritative server for the domain.
- The authoritative server returns the IP address for example.com.
- The resolver returns the IP address to your browser, which then requests the page.
After step eight, the browser makes an HTTP request to that IP address and the web server returns the page. You can see the chain yourself with dig +trace example.com, which shows each referral in turn.
What is the difference between recursive and iterative queries?
In a recursive query, the client asks a server to return the final answer or an error, and the server does all the follow-up work. In an iterative query, a server returns the best answer it has — usually a referral to another server — and the client follows it.
In practice, the two modes combine. Your device sends a recursive query to the recursive resolver, and the resolver then sends iterative queries down the hierarchy: root, TLD, authoritative. Each server in that walk returns a referral, not the final answer, until the last one.
RFC 1034 describes both approaches and notes that the iterative approach is required, while the recursive approach is allowed as an option. That design keeps the load spread across servers instead of piling it on the root.
How does DNS caching and TTL work?
DNS caching stores an answer closer to the client so the next lookup for the same name is faster. Caching happens in the browser, the operating system, the router, and the recursive resolver, and each cached record carries a time-to-live.
The TTL is set by the owner of the record and tells a resolver how many seconds it may keep the answer. When the TTL expires, the resolver must ask again. A short TTL means changes spread quickly; a long TTL means fewer lookups and less load.
Caching is why most lookups end quickly. If the resolver already has the answer, or already knows the authoritative servers for a domain, it skips the root and TLD steps entirely. You can try this yourself with our free DNS lookup tool.
What DNS record types can a server return?
An authoritative server holds records for its zone, each with a type, a name, a TTL and data. The type tells the resolver what the record means, and different types serve different jobs.
| Record | What it does | Example use |
|---|---|---|
| A | Maps a name to an IPv4 address | example.com to 93.184.216.34 |
| AAAA | Maps a name to an IPv6 address | IPv6-only clients and networks |
| CNAME | Aliases one name to another | www pointing at a CDN hostname |
| MX | Lists mail servers for a domain | Delivering email to the right server |
| NS | Lists authoritative servers for a zone | Delegation from parent to child zone |
| TXT | Holds text data | SPF, DKIM and domain verification |
If the answer is a CNAME, the resolver must start a new chase for the target name, which adds one or more steps. That is common with CDN hostnames, where a name points to another name before it points to an IP address.
Why does DNS resolution fail?
DNS fails when any link in the chain breaks: your device has the wrong resolver, the resolver is down, the authoritative server has a wrong or expired record, or the network drops the query. The error you see is usually the same — the site does not load — whatever the cause.
Start with the simplest checks. Flush your local cache with ipconfig /flushdns on Windows, then try a public resolver such as 8.8.8.8 or 1.1.1.1. If the site loads with a different resolver, your usual resolver or its cache is the problem.
For a domain you own, check the records with dig or our DNS lookup tool. A missing or wrong NS record at the registrar is a common cause of a domain that never resolves.
You can also check who runs the domain with our WHOIS lookup to confirm the registrar and nameservers are correct.
How is DNS protected against spoofing?
DNS was not designed with security built in, so attackers can try to poison a cache or spoof an answer and send you to a fake site. Three defences matter most: DNSSEC, encrypted DNS, and a trustworthy resolver.
DNSSEC adds signatures to DNS records so a resolver can check that the answer came from the authoritative server and was not changed in transit. It does not encrypt the query, but it does prove the answer is genuine.
Encrypted DNS, in the form of DNS over TLS on port 853 and DNS over HTTPS on port 443, hides the query from anyone watching the network. Together with DNSSEC and a resolver you trust, they close the most common DNS attacks. For more on protecting your own domain, see our guide to DMARC.
The bottom line
A DNS lookup is a short, practical chain: your device asks a recursive resolver, the resolver checks its cache, then walks from the root to the TLD to the authoritative server, and the answer comes back with a TTL attached.
Most of the time the cache answers and the walk never happens. When a lookup does fail, work through the chain in order — local cache, resolver, records — and you will find the break. You can start by checking any domain with the free DNS lookup tool.
Frequently asked questions
How long does DNS resolution take?
A cached lookup usually returns in milliseconds. A cold lookup that must walk from the root to the authoritative server takes longer, but still usually finishes in well under a second on a normal connection.
What is the difference between a recursive and an authoritative DNS server?
A recursive resolver takes your query and does the work of finding the answer, asking other servers as needed. An authoritative server holds the actual records for a domain and gives the final answer for that zone.
What is a DNS root server?
A root server holds the root zone, which lists the servers for every top-level domain such as .com and .org. There are 13 logical root server identities, labelled A to M, run by 12 organisations and replicated worldwide.
What is a TLD server?
A top-level domain server holds the servers for one top-level domain, such as .com. It answers a resolver by pointing it to the authoritative servers for the domain you asked about.
What does TTL mean in DNS?
TTL, or time-to-live, is the number of seconds a resolver may keep a DNS record in its cache. When the TTL expires, the resolver must ask again. Short TTLs update faster; long TTLs reduce load.
Why does DNS sometimes fail?
Common causes are a wrong DNS setting, a resolver outage, an expired or misconfigured record at the authoritative server, or a network problem. Flushing your local cache and trying a public resolver such as 8.8.8.8 or 1.1.1.1 can help narrow it down.
What is DNSSEC?
DNSSEC adds cryptographic signatures to DNS records so a resolver can check that the answer really came from the authoritative server and was not changed in transit. It protects against DNS spoofing and cache poisoning.
Does DNS use UDP or TCP?
DNS usually uses UDP on port 53 for small queries, and TCP when the answer is large or for zone transfers. Encrypted DNS uses port 853 for DNS over TLS and port 443 for DNS over HTTPS.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against RFC 1034 and RFC 1035 and Cloudflare's DNS learning guide, which describes the eight steps of a DNS lookup.
How we write and fact-check →