How DNS Works: The Step-by-Step Domain Name Resolution Process

DNS works by running a step-by-step lookup across local caches and 4 DNS server layers to convert a domain name into an IP address in milliseconds. Your device checks its browser and operating system caches first before asking a recursive resolver to track down the answer. The speed of a DNS lookup depends on Time to Live (TTL) caching.

Browser Resolver Root+TLD Authoritative Website query solid = query · dashed = cached response · every hop caches until TTL
The DNS resolution path from browser to website

What Happens on Your Device Before a DNS Query Enters the Network?

A client device executes 4 local pre-resolution checks across the application, browser cache, local hosts file, and operating system stub resolver before transmitting a DNS packet over the network.

Client operating systems process hostname requests through 4 local stages:

  1. Validate whether the destination string is already an IPv4 address (such as 192.0.2.1) or an IPv6 literal using a regular expression check, which skips DNS resolution entirely if matched.
  2. Inspect the application or web browser internal DNS cache (such as Chromium's in-memory host cache at chrome://net-internals/#dns) for an active, unexpired address mapping.
  3. Parse the local static hosts file (/etc/hosts on Linux and macOS, or C:\Windows\System32\drivers\etc\hosts on Windows) for manual hostname-to-IP overrides such as 127.0.0.1 localhost.
  4. Query the operating system stub resolver daemon: Windows DNS Client (dnscache), macOS mDNSResponder, or Linux systemd-resolved (governed by /etc/nsswitch.conf) to retrieve records cached at the OS kernel or service level.

Evaluating these local checkpoints first eliminates unnecessary network queries whenever an application or operating system already holds a valid address record.

How Does a Device Know Which DNS Server to Contact First?

A client device discovers its primary recursive DNS server IP address through 3 configuration mechanisms: Dynamic Host Configuration Protocol (DHCP), IPv6 Router Advertisements, or manual network interface settings.

On IPv4 local area networks, routers provide local recursive server addresses through DHCP when the device connects. On IPv6 networks, routers advertise recursive DNS server addresses via multicast IPv6 Router Advertisements (RFC 8106 RDNSS). Network administrators can override automatic router settings by assigning manual public resolvers, including Cloudflare (1.1.1.1), Google Public DNS (8.8.8.8), AliDNS (223.5.5.5), and Quad9 (9.9.9.9). Administrators clear stale OS stub entries using the commands in How to Flush DNS Cache when local resolver settings change.

How Does a Recursive DNS Lookup Work Across the 4 Server Tiers?

A recursive DNS lookup resolves an uncached domain by executing 8 network query and response steps across the recursive resolver, root nameserver, TLD nameserver, and authoritative nameserver.

A cold, uncached DNS lookup executes 8 sequential network steps:

  1. Transmit a UDP port 53 query (or encrypted DoH/DoT request) with the Recursion Desired (RD=1) flag from the OS stub resolver to the configured recursive resolver (such as 1.1.1.1).
  2. Send an iterative query (RD=0) from the recursive resolver to a root nameserver (.) using an IP address preloaded in the resolver's root hints file.
  3. Return a referral response from the root nameserver containing the NS records for the Top-Level Domain (such as a.gtld-servers.net for .com) along with their IPv4 and IPv6 glue records in the ADDITIONAL section.
  4. Issue an iterative query from the recursive resolver to one of the .com TLD nameservers.
  5. Respond from the TLD nameserver with the authoritative NS delegation records for the target domain (such as ns1.example.com and ns2.example.com) and any required in-bailiwick glue records.
  6. Query the domain's authoritative nameserver from the recursive resolver for the requested QNAME (example.com) and QTYPE (A or AAAA).
  7. Answer from the authoritative nameserver with the Authoritative Answer (AA=1) flag set, returning the IP address (such as 93.184.216.34) and its Time to Live (TTL) in the ANSWER section.
  8. Cache the resource record at the recursive resolver for the TTL duration and return the final response (with Recursion Available RA=1) to the client stub resolver and browser.

Each server in the 8-step lookup performs a specialized lookup or referral role. The table below summarizes the 4 DNS servers in the resolution chain by role, operator, and returned data.

ServerRoleExample
Recursive resolverChases the answer across the hierarchy on your behalfCloudflare 1.1.1.1, Google 8.8.8.8
Root nameserverPoints to the TLD nameserver for the extensiona.root-servers.net through m.root-servers.net
TLD nameserverHolds delegation for every domain in its extensionVerisign for .com
Authoritative nameserverHolds the zone file and returns the final recordYour DNS host

Intermediate caching streamlines this resolution sequence significantly. A recursive resolver caches the .com TLD referral across all subsequent queries and skips Steps 2 and 3 during that 48-hour window because TLD registries publish NS delegation records with a 172,800-second (48-hour) TTL. Administrators can compare fundamental system architecture in the What Is DNS guide or benchmark cold versus cached lookup latency with the DNS Response Time Test.

How Do Root Hints Priming and Glue Records Prevent Circular Dependencies?

Root hints files and glue records prevent circular DNS resolution loops by supplying hardcoded IP addresses for root servers and inline IP addresses for in-bailiwick authoritative nameservers.

Every recursive resolver (such as BIND, Unbound, or Knot Resolver) requires known destination addresses to begin resolution. Resolvers overcome this bootstrap problem by shipping with an IANA root hints file (named.root) containing hardcoded IPv4 and IPv6 addresses for the 13 root server clusters (a.root-servers.net to m.root-servers.net). On initial startup, the resolver issues a priming query, an NS query directed to the root zone (.), which fetches the authoritative, current Anycast IP addresses for all 13 root server clusters.

A second circular dependency arises when a domain uses its own subdomains as authoritative nameservers. In this setup, a recursive resolver cannot resolve example.com without first knowing the IP address of ns1.example.com if example.com uses its own in-bailiwick subdomain ns1.example.com as its authoritative nameserver. The parent TLD registry breaks this circular dependency by publishing glue records (A and AAAA records for ns1.example.com) directly inside the ADDITIONAL section of the TLD referral response. Domain administrators can verify parent-child delegation integrity using the Glue Record Checker and DNS Delegation Checker.

What Is Inside a DNS Packet? (5 Message Sections and 7 Header Flags)

Every DNS query and response uses a single wire message format consisting of a fixed 12-byte header followed by 4 variable-length data sections. The table below details the 5 DNS packet sections and the 7 header control flags that govern resolution behavior.

Packet Component / FlagBit Size / SectionRFC SpecificationFunction in DNS Resolution
HEADER Section12 bytes (96 bits)RFC 1035 §4.1.1Carries the 16-bit Transaction ID (ID), 16-bit Flags field, and record section counters (QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT).
QUESTION SectionVariableRFC 1035 §4.1.2Contains the queried domain name (QNAME), record type (QTYPE, such as A = 1), and class (QCLASS, IN = 1).
ANSWER SectionVariableRFC 1035 §4.1.3Carries the resource records (RRs) that directly answer the question. Empty in outbound queries and referral responses.
AUTHORITY SectionVariableRFC 1035 §4.1.3 / RFC 2308Carries NS records during TLD referrals, or the zone's SOA record during negative NXDOMAIN responses to set negative cache TTL.
ADDITIONAL SectionVariableRFC 1035 §4.1.3 / RFC 6891Carries glue A/AAAA records for nameservers in AUTHORITY, plus the OPT pseudo-record for EDNS0 payload negotiation.
QR & AA Flags1 bit eachRFC 1035 §4.1.1QR distinguishes a Query (0) from a Response (1). AA=1 certifies that the responding server is authoritative for the domain.
TC (Truncated) Flag1 bitRFC 1035 / RFC 7766TC=1 indicates the response exceeded the UDP packet size limit (512 bytes, or up to 4,096 bytes with EDNS0), instructing the client to retry immediately over TCP port 53.
RD & RA Flags1 bit eachRFC 1035 §4.1.1RD=1 requests recursive resolution from the client. RA=1 in the response confirms the server supports recursion.
AD & CD Flags1 bit eachRFC 4035 §3.2AD=1 (Authenticated Data) confirms the resolver verified DNSSEC signatures. CD=1 (Checking Disabled) tells the resolver to return records even if DNSSEC validation fails.

The 16-bit Transaction ID (ID) combined with randomized UDP source ports provides critical protocol security. Resolvers match incoming responses to outstanding queries by verifying that the source IP address, destination port, and 16-bit ID match exactly. Because 16 bits yield only 65,536 possible transaction IDs, port randomization increases the entropy space to billions of permutations, preventing off-path attackers from forging malicious responses before the authoritative server replies. DNSSEC signs each record set when cryptographic data integrity is required, as detailed in the What Is DNSSEC guide.

How Does DNS Resolution Handle CNAME Chains and Subdomain Redirects?

DNS resolution handles a CNAME (Canonical Name) record by restarting the lookup process for the target alias hostname until the recursive resolver reaches a final A or AAAA IP address.

The authoritative nameserver returns a record stating that shop.example.com aliases to stores.myshopify.com when a client requests an alias hostname (such as shop.example.com). Because the canonical target belongs to an external domain, the recursive resolver initiates a new resolution pass across the .myshopify.com TLD and authoritative nameservers to obtain its IP address. Once resolved, the recursor packages both the CNAME mapping and the final A record into the ANSWER section for the client browser.

The authoritative nameserver includes both the CNAME record and the target A record in a single response packet (1 RTT) if both the alias and target reside in the same zone file. The DNS specification strictly forbids CNAME records on zone apex hostnames, a restriction managed by modern DNS providers through CNAME Flattening.

How Does Reverse DNS Resolution (PTR Lookup) Work Compared to Forward DNS?

Forward DNS resolves a domain name to an IP address using A and AAAA records, whereas reverse DNS (rDNS) resolves an IP address back to a hostname by querying a PTR record inside the special .arpa top-level domain.

The DNS hierarchy organizes domain names from right to left (top-level domain .com on the right, specific subdomain on the left). In contrast, IP addresses read from left to right (network prefix 192.0.2.0/24 on the left, host identifier .25 on the right). To map IP addresses into the existing right-to-left tree structure, reverse DNS inverts the IP octets so that broader network allocations align with higher namespace levels.

An IPv4 address such as 192.0.2.25 reverses its 4 octets and appends the in-addr.arpa domain, creating 25.2.0.192.in-addr.arpa. An IPv6 address reverses each individual 4-bit hexadecimal nibble under the ip6.arpa domain. Mail transfer agents rely heavily on reverse DNS to verify connecting SMTP servers, which administrators can inspect directly using the PTR Record Lookup tool.

How Do You Trace a Live DNS Lookup Step by Step Using dig +trace?

To trace every hop of the DNS resolution chain from your terminal, run the command dig +trace example.com to force iterative queries from the root zone down to the authoritative nameserver.

Executing an iterative trace outputs the sequential delegation path across the 4 DNS tiers:

$ dig +trace example.com

; <<>> DiG 9.18 <<>> +trace example.com
.                       518400  IN  NS  a.root-servers.net.
;; Received 525 bytes from 1.1.1.1#53(1.1.1.1) in 14 ms

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

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

example.com.            3600    IN  A   93.184.216.34
;; Received 56 bytes from 199.43.135.53#53(a.iana-servers.net) in 18 ms

The terminal output demonstrates the 4 referral tiers: the local recursive resolver supplies root nameserver NS records (hop 1), the root nameserver refers to .com TLD nameservers (hop 2), the TLD nameserver refers to authoritative nameservers (hop 3), and the authoritative nameserver returns the definitive A record with its 3600-second TTL (hop 4). On Windows environments, administrators can inspect authoritative servers using nslookup -type=ns example.com, or verify multi-resolver consensus worldwide using the browser-based DNS Propagation Checker.

What Happens in the DNS Hierarchy When You Register a New Domain?

Registering a new domain name triggers 5 provisioning steps that connect your domain registrar, the TLD registry, and your authoritative DNS zone so global recursive resolvers can locate your site.

Domain provisioning links the registry hierarchy through 5 sequential steps:

  1. Submit the domain registration and chosen authoritative nameservers (such as ns1.provider.com and ns2.provider.com) through an ICANN-accredited registrar using the Extensible Provisioning Protocol (EPP).
  2. Record the domain delegation in the Top-Level Domain registry database (such as Verisign for .com) and publish the parent NS records into the TLD zone file.
  3. Initialize the authoritative DNS zone file at your DNS hosting provider with a mandatory SOA (Start of Authority) record and matching NS records.
  4. Publish functional resource records inside the authoritative zone file, including A and AAAA records for web servers and MX, SPF, DKIM, and DMARC records for email routing and authentication.
  5. Propagate the delegation across recursive resolvers as TLD caches refresh, allowing any client worldwide to complete the step-by-step DNS resolution process.

Once domain delegation is active, every web request, API call, and SMTP delivery relies on uninterrupted recursive-to-authoritative DNS lookups bounded by record cache lifetimes. Domain owners maintaining production infrastructure can evaluate cache expiration rules in the DNS TTL Explained guide and monitor zone configuration health with live DNS lookup utilities.

Frequently asked questions

How many steps are in a DNS lookup?+

An uncached DNS lookup takes 8 network steps across 4 server tiers (client stub resolver, recursive resolver, root nameserver, TLD nameserver, and authoritative nameserver) after checking 4 local caches on the device.

Why does my computer not ask the root server every time?+

Recursive resolvers cache both final resource records and intermediate TLD and authoritative NS referrals for the duration of their Time to Live (TTL), allowing subsequent lookups to bypass root servers during the 48-hour TLD referral window.

How long does a DNS lookup take in milliseconds?+

A cached DNS lookup completes in 1 to 15 milliseconds from a local or nearby Anycast recursive resolver, while a cold uncached lookup traversing root, TLD, and authoritative servers takes 40 to 250 milliseconds. In real-world performance tuning, we recommend keeping intermediate TTLs between 300 and 3600 seconds so repeat visitors benefit from hot resolver caches without suffering protracted cache delays during migrations.

What happens if a DNS response is larger than 512 bytes?+

The server sets the Truncated (TC=1) header flag and prompts the client to retry over TCP port 53 if a DNS response exceeds the 512-byte UDP limit or 4,096-byte EDNS0 buffer. In practice, the most common operational failure occurs when security teams drop TCP port 53 at the firewall perimeter, causing truncated DNSSEC responses or large TXT record queries to timeout indefinitely.

Last verified: 2026-10-31