How does DNS resolve a domain name into an IP address?
Interview preparation resource from Gate Smashers.
DNS resolves a domain name by asking a recursive resolver to find the relevant DNS record, usually an A record for IPv4 or an AAAA record for IPv6. The resolver first checks its cache. On a cache miss, it follows the DNS delegation hierarchy—root servers, top-level-domain servers, and the domain’s authoritative servers—then returns the result to the client and caches it according to its TTL.

Client query and caching
When an application needs an address for a name such as example.com, it sends a DNS query to a configured recursive resolver. The application, operating system, or resolver may already have a usable cached answer, in which case no external DNS lookup is needed.
The recursive resolver is commonly supplied by an organization, ISP, router, or public DNS provider. It performs the lookup on the client's behalf when it does not have a cached answer.
DNS hierarchy and delegation
For an uncached name, the resolver typically begins by querying a root DNS server. The root server does not usually provide the final address; it returns a referral to the servers responsible for the relevant top-level domain, such as .com.
The resolver then queries a top-level-domain server, which returns a referral to the authoritative name servers for the domain. Finally, the resolver queries an authoritative server, which provides the requested DNS record or another applicable response.
- Root servers: Refer the resolver to the appropriate top-level-domain servers.
- TLD servers: Refer the resolver to the domain's authoritative name servers.
- Authoritative servers: Provide the domain's DNS data, such as A, AAAA, or CNAME records.
Aliases, responses, and caching
An A record contains an IPv4 address, while an AAAA record contains an IPv6 address. If the queried name has a CNAME record, the resolver follows the alias to its target name and resolves that target as needed.
The resolver returns the resulting DNS response to the client. It normally caches cacheable data for the TTL specified in the DNS records, allowing later queries to be answered more quickly until the cached entry expires.
Transport
Traditional DNS queries commonly use UDP port 53. TCP port 53 is used when needed, including for zone transfers and for responses that cannot be handled over UDP.
