How the Domain Name System (DNS) Works

How the Domain Name System (DNS) Works

Demystifying DNS, Nameservers, A Records, and IP Routing. Learn how your browser translates human-readable names to server locations.

Technology TLDix Editorial Team Published: Updated: 7 min read

Every time you open a website, send an email or call an API, your device first has to answer a simple question: which IP address belongs to this name? The Domain Name System (DNS) is the global, distributed directory that answers it. It is one of the oldest pieces of internet infrastructure still in daily use, and because it usually works invisibly, many site owners only learn how it operates when something breaks. This guide walks through the full journey of a DNS query in plain language, explains why caching matters so much, and shows the commands you can use to see it all for yourself.

What DNS actually does

Computers route traffic using numeric addresses such as 93.184.215.14 (IPv4) or 2606:2800:21f:cb07:6820:80da:af6b:8b2c (IPv6). People prefer names. DNS maps between the two, but it is more than a lookup table. It is a hierarchical, delegated database: no single server knows every answer. Instead, responsibility is split into zones, and each zone is managed by whoever controls it.

⚡ TLDix Instant Tools

Inspect Any Domain and Web Hosting Instantly

Inspect the infrastructure of any domain or website in seconds using TLDix WHOIS Domain, Hosting Lookup and Domain Oracle (AI).

🔍 Domain WHOIS 🖥️ Hosting Lookup 🔮 Domain Oracle ✨ Sign Up Free →

This design has three practical consequences:

  • Scalability: the root servers do not need to know about billions of hostnames, only where to find each top-level domain.
  • Autonomy: once a domain is delegated to you, you decide what records it contains without asking anyone else.
  • Resilience: every level is served by multiple servers, often spread across continents with anycast routing.

The individual entries inside a zone, such as A, AAAA, CNAME and MX, are covered in detail in our guide to understanding DNS records. Here we focus on how a resolver finds those records in the first place.

The DNS hierarchy: root, TLD and authoritative servers

Read a domain name from right to left and you are reading the DNS tree from the top down. The name www.example.com. actually ends with an invisible dot that represents the root.

LevelExampleWho operates itWhat it knows
Root.12 organisations running 13 named root server identities (a to m), each with many anycast instancesWhich servers are authoritative for every TLD
Top-level domain (TLD)com., de., com.tr.The registry (for example Verisign for .com, DENIC for .de)Which name servers are authoritative for each registered domain
Second-level domainexample.com.The domain holder, usually via a DNS provider or hostThe actual records: addresses, mail servers, text records
Subdomainwww.example.com.Same as the parent zone, unless delegated furtherRecords for that specific host

The link between levels is called delegation. When you register a domain and set its name servers at your registrar, the registrar passes those NS records to the registry, which publishes them in the TLD zone. If the name servers live inside the domain itself (for example ns1.example.com), the registry also publishes glue records, which are the IP addresses of those servers, to avoid a chicken-and-egg problem.

Step by step: what happens when you type a URL

Suppose you visit www.example.com for the first time on a fresh network. The lookup proceeds roughly like this:

  1. Local checks. The browser checks its own cache, then asks the operating system. The OS consults its cache and the hosts file.
  2. Stub resolver to recursive resolver. If nothing is cached, the stub resolver built into your OS sends a query to the configured recursive resolver: usually your ISP, your router, or a public service such as 1.1.1.1, 8.8.8.8 or 9.9.9.9.
  3. Recursive resolver asks a root server. The resolver ships with a list of root server addresses (the root hints). It asks one of them about www.example.com. The root does not know the answer but replies with a referral: here are the name servers for .com.
  4. Recursive resolver asks the TLD servers. A .com server replies with another referral: the authoritative name servers for example.com, plus glue if needed.
  5. Recursive resolver asks the authoritative server. This server holds the zone and returns the actual answer, for example an A record with an IPv4 address, and sets the AA (authoritative answer) flag.
  6. Answer returned and cached. The resolver passes the answer back to your device and stores it, along with the referrals it collected, for the duration of each record’s TTL.

The resolver performs iterative queries towards the hierarchy while answering your device’s recursive query. Your laptop asks once and waits; the resolver does the walking. In practice, steps 3 and 4 are rarely needed because the resolver already has the root and .com referrals cached.

Watching it with dig +trace

The dig utility (part of BIND tools, available on Linux and macOS) can perform the walk itself and print each referral. Output below is shortened:

$ dig +trace www.example.com A

.                 518400  IN  NS  a.root-servers.net.
.                 518400  IN  NS  b.root-servers.net.
;; Received 239 bytes from 127.0.0.53#53

com.              172800  IN  NS  a.gtld-servers.net.
com.              172800  IN  NS  b.gtld-servers.net.
;; Received 1170 bytes from 198.41.0.4#53(a.root-servers.net)

example.com.      172800  IN  NS  a.iana-servers.net.
example.com.      172800  IN  NS  b.iana-servers.net.
;; Received 361 bytes from 192.5.6.30#53(a.gtld-servers.net)

www.example.com.  300     IN  A   93.184.215.14
;; Received 60 bytes from 199.43.135.53#53(a.iana-servers.net)

Each block is one hop: root, TLD, authoritative. The number after the name is the TTL in seconds.

Caching and TTL: why DNS is fast

If every lookup walked the full tree, the root and TLD servers would be overwhelmed and browsing would feel sluggish. Caching prevents that. Every record carries a Time To Live (TTL), set by the zone owner, telling resolvers how many seconds they may reuse the answer before asking again.

  • Long TTLs (hours or a day) reduce query load and make your site more tolerant of brief authoritative outages, but changes take longer to reach everyone.
  • Short TTLs (60 to 300 seconds) let you switch servers quickly, at the cost of more queries.
  • Negative caching: a "this name does not exist" (NXDOMAIN) answer is also cached, for a period derived from the zone’s SOA record. Creating a record right after someone queried it can therefore seem not to work for a while.

A practical habit before a migration: lower the TTL of the records you plan to change a day or two in advance, make the switch, then raise the TTL again once traffic has moved.

What "DNS propagation" really means

Nothing is actively pushed around the internet when you edit a record. "Propagation" is simply the time it takes for cached copies to expire across thousands of resolvers. Two different timers are involved:

  • Changes to records inside your zone are governed by those records’ TTLs.
  • Changes to your name servers involve the delegation published in the TLD zone, whose NS TTL is set by the registry and is often 48 hours or more for some TLDs. Resolvers that cached the old delegation keep using it until it expires.

Keep the old DNS provider serving the same records during a name server switch, and the transition will be invisible to visitors.

Common DNS problems and how to spot them

SymptomLikely causeHow to check
NXDOMAIN for a domain you ownDomain expired, suspended, or delegation removed at the registryCheck status and expiry in a WHOIS/RDAP lookup
SERVFAIL from resolversAuthoritative servers unreachable, lame delegation, or a broken DNSSEC chaindig @ns1.yourdns.net example.com and dig +trace
Some users see the old siteCached records still within TTLQuery several public resolvers and compare
Email stops but web worksMX or SPF records missing after a provider movedig example.com MX

A lame delegation happens when the TLD points to name servers that do not actually serve your zone, often after cancelling a hosting plan without updating NS records. You can quickly see which name servers a domain is delegated to, along with its registrar and expiry date, using the TLDix WHOIS lookup.

Recursive resolvers, privacy and security

Classic DNS travels over UDP port 53 in plain text, so anyone on the network path can see and potentially tamper with queries. Several improvements address this:

  • DNS over TLS (DoT) and DNS over HTTPS (DoH) encrypt the connection between your device and the recursive resolver, protecting privacy on the first hop.
  • QNAME minimisation makes resolvers send only the part of the name each server needs, so the root does not learn the full hostname you are looking up.
  • DNSSEC adds cryptographic signatures so resolvers can verify that answers really came from the zone owner and were not altered. Encryption hides queries; DNSSEC proves authenticity. They solve different problems and work well together.

Keeping your domain’s DNS healthy

Most DNS outages are not exotic attacks. They are ordinary oversights: an expired domain, a forgotten DNS hosting account, or a name server change nobody documented. A simple routine helps:

  1. Use at least two authoritative name servers, ideally on separate networks.
  2. Document which provider hosts your zone and who has access.
  3. Keep the domain’s registration and the DNS hosting account renewed and on auto-renew where possible.
  4. Check delegation after any provider change with dig NS and dig +trace.
  5. Monitor expiry dates centrally. In the TLDix domain panel you can track domains, SSL certificates and hosting renewals in one place and get reminded before anything lapses.

Once you understand the chain from root to authoritative server, most DNS mysteries become straightforward: find which link is returning the unexpected answer, check its TTL, and fix the data at the source.

Frequently asked questions

How long does a DNS lookup normally take?
When the answer is already cached by your recursive resolver, a lookup usually completes in a few milliseconds. A completely uncached lookup that has to contact root, TLD and authoritative servers may take tens to a few hundred milliseconds, depending on network distance and server response times. Browsers and operating systems also keep their own short-lived caches, so repeat visits are often instant.
Can I speed up DNS changes that are not showing yet?
You cannot force other resolvers to drop their caches, but you can flush your own. Clear the browser DNS cache, flush the operating system cache, and try a public resolver directly. For future changes, lower the record’s TTL a day or two beforehand so caches expire quickly when you make the switch, then raise it again afterwards.
Is changing my DNS resolver to a public one safe?
Reputable public resolvers are generally safe and often support DNSSEC validation and encrypted DNS over HTTPS or TLS. The trade-off is that the resolver operator sees the names you look up, so read its privacy policy. Some corporate or ISP networks rely on their own resolvers for internal names, so switching may break access to internal services.
What is the difference between a registrar and a DNS provider?
The registrar is where you register and renew the domain and where you set which name servers it uses. The DNS provider runs those authoritative name servers and hosts your zone records. They can be the same company or different ones. If either the registration or the DNS hosting lapses, resolution for the domain can fail.
Why does my domain resolve on one network but not another?
Different networks use different recursive resolvers, and each caches answers independently. One may still hold an old record within its TTL, cache a negative NXDOMAIN response, or perform DNSSEC validation that fails while another does not. Comparing answers from several resolvers with dig and running dig +trace usually reveals which step differs.
Frequently Asked Questions

Everything You Need to Know

Find answers about domain lookups, WHOIS, pricing, and AI Domain Oracle on TLDix.com.