[ learn ]

How DNS works

Updated · 4 min read

Short answer

The Domain Name System (DNS) is the internet's directory: it turns names like google.com into the IP addresses computers connect to. Your device asks a recursive resolver, which finds the answer by asking the root, then the TLD servers, then the domain's authoritative name servers, and caches the result for as long as its TTL allows.

What happens in a lookup

When you open www.example.com:

  1. Your device checks its own cache, then asks its configured resolver, usually your ISP's or a public one such as 1.1.1.1 or 8.8.8.8.
  2. If the resolver has no cached answer, it asks a root server, which replies "ask the .com servers" with their addresses.
  3. It asks a .com TLD server, which replies with the name servers for example.com (its NS records).
  4. It asks one of those authoritative servers, which gives the actual answer, such as an A record with an IPv4 address.
  5. The resolver returns the answer to your device and caches it.

All this usually takes a few tens of milliseconds, and much less when the answer is cached. Queries traditionally travel unencrypted over UDP or TCP port 53; DNS over HTTPS (DoH) and DNS over TLS (DoT) encrypt them between your device and the resolver.

The servers involved

  • Recursive resolver: does the legwork for clients and caches answers. It knows nothing by itself.
  • Root servers: know where every TLD's servers are. There are 13 named root server identities, a to m, run by 12 organisations, but each is copied to many locations with anycast, so there are well over a thousand root server instances worldwide.
  • TLD servers: run by each registry, they know which name servers each registered domain uses.
  • Authoritative servers: hold a domain's records, set by the owner, often at a DNS host or CDN.

Caching and TTL

Every record has a TTL (time to live) in seconds: how long resolvers may keep it before asking again. A TTL of 300 means up to five minutes; 86400 means a day. Short TTLs make changes take effect quickly, long TTLs cut lookups and survive short outages. Failed lookups are cached too ("negative caching").

That is why DNS changes "propagate": nothing is pushed out, old answers simply expire from caches around the world at different times. Lower the TTL a day before a planned move, then raise it again afterwards.

Common record types

TypeHoldsExample
AAn IPv4 addressexample.com → 192.0.2.10
AAAAAn IPv6 addressexample.com → 2001:db8::10
CNAMEAn alias to another namewww → example.cdn-provider.net
MXMail servers, with priority10 mail.example.com
NSThe domain's authoritative name serversns1.dns-host.net
TXTFree text: SPF, DKIM, DMARC, verification tokensv=spf1 include:_spf.google.com ~all
SOAZone details: primary server, contact, serial, timersOne per zone
CAAWhich certificate authorities may issue TLS certificates0 issue "letsencrypt.org"
PTRReverse DNS: IP address to name8.8.8.8 → dns.google

A CNAME cannot sit alongside other records on the same name, which is why it cannot be used at the bare domain (example.com); many DNS hosts offer a "flattening" or ALIAS feature instead. The addresses in this table are documentation examples.

DNS and your location

Large sites answer the same name with different addresses depending on where the resolver is, to send you to a nearby server. So google.com resolves differently in Kuala Lumpur and in London. Using a distant public resolver can therefore send you to a farther server, unless the resolver passes a hint about your network (EDNS Client Subnet). Each address returned belongs to a network you can inspect with the IP lookup.

Try it

The DNS lookup on this site queries all the common types at once: try /dns/google.com, or enter an IP address to get its reverse DNS. From a terminal:

dig google.com A +short
dig google.com MX +short
nslookup -type=TXT google.com

The returned addresses can then be checked with IP lookup to see their ASN and location.

[ FAQ ]

Frequently asked questions

How long does a DNS change take?

Up to the old record's TTL, because resolvers keep the old answer until it expires. With a TTL of 300 seconds most users see the change within minutes; with 86400 it can take a day. Changes of name servers at the registry can take longer.

What is the difference between an A and an AAAA record?

An A record points a name to an IPv4 address, an AAAA record to an IPv6 address. A name can have both, and devices with IPv6 usually prefer the AAAA address.

Should I use a public DNS resolver?

It can be faster, more reliable or more private than your ISP's, and may support encrypted DNS. Public resolvers such as 1.1.1.1, 8.8.8.8 and 9.9.9.9 each have their own privacy policies. Your ISP can still see which IP addresses you connect to.

Why does the same domain return different IP addresses?

Large sites use several servers and CDNs, and answer according to the resolver's location, load and IP version. Rotating answers and short TTLs are normal and do not indicate a problem.

Last updated · All articles · API docs