How DNS converts domain names to IP addresses

Learn how DNS converts human-friendly domain names into computer-friendly IP addresses, and how resulting entries are cached along the way.

M Bytes Newsletter
Get the developer newsletter

    Fresh bytes every Thursday. No spam, ever. Unsubscribe anytime.

    Join 9,000+ developers and get three free video lessons every week.

    When you type a domain name like google.com into your browser, your computer needs to figure out where that website actually lives on the internet. That's where DNS comes in - it converts human-friendly domain names into computer-friendly IP addresses.

    Let's walk through exactly how this works.

    Your computer first checks its DNS cache - basically a notepad where it keeps IP addresses it's already looked up. If you've visited google.com recently, your computer already knows where to find it.

    If there's no cached entry, your computer starts at one of the internet's 13 root nameservers. Think of these as the internet's primary directory:

    Request:
     
    "Hey root server, where can I find google.com?"
     
    Response:
     
    "For .com domains, talk to the .com nameservers at 192.5.6.30"

    Next stop is the .com nameservers. They keep track of every .com domain and know exactly which nameservers handle each one:

    Request:
     
    "Hi .com nameserver, I'm looking for google.com"
     
    Response:
     
    "Google.com's nameservers are at ns1.google.com - they'll have the IP you need"

    Want to see who manages any domain? Try running: whois google.com

    Finally, we reach Google's own nameservers. These servers are the authority on everything google.com:

    Request:
     
    "I need google.com's address"
     
    Response:
     
    "Its IP is 172.217.4.46, and this answer is good for 300 seconds"

    This whole process happens in milliseconds, with results getting cached at each step.

    Want to see this in action? The dig command lets you watch the entire lookup process:

    dig +trace google.com

    You'll see the complete journey, ending with the final DNS record:

    google.com.		300	IN	A	172.217.4.46

    That IP address is google.com's actual location. The "300" is the TTL (Time To Live) - how long DNS servers should cache this info before checking for updates.

    Fun fact: Each DNS server maintains its own cache. If your ISP's DNS server already has the answer cached, it'll skip the remaining steps entirely. This makes future requests faster and keeps the DNS system running smoothly.