Skip to main content

What is TTL in DNS?

TTL (Time To Live) in DNS is the lifetime of a DNS record in cache, measured in seconds.

In simpler terms: TTL shows how long a DNS answer can be stored and used without asking the DNS server again.


Why TTL is needed

DNS queries can be made by:

  • the browser
  • the operating system
  • the provider's DNS servers

To avoid asking the DNS server every time, caching is used. TTL says:

"This answer can be considered valid for N seconds."


How TTL works (a simple example)

Suppose a record has:

example.com A 93.184.216.34 TTL = 300

This means:

  • the DNS answer is cached for 300 seconds (5 minutes)
  • during this time the IP is taken from cache
  • new queries do not go to the authoritative DNS

After the TTL expires:

  • the record is removed from cache
  • on the next request, DNS is queried again

Where TTL applies

TTL is taken into account:

  • in the browser
  • in the OS
  • in recursive DNS servers
  • in proxies and CDNs

TTL is not the same as the lifetime of the record on the server, only the caching time.


Why TTL matters

High TTL

  • fewer DNS queries
  • faster performance
  • slow propagation of changes

Low TTL

  • changes take effect quickly
  • more DNS queries
  • higher load

TTL is a trade-off between speed and flexibility.


A common real-world scenario

Before migrating a site:

  • TTL is lowered (for example, to 60 seconds)
  • the IP is changed
  • after the migration, TTL is raised back

This allows:

  • minimizing downtime
  • switching users over faster

Real-life example

TTL is like the validity period of a certificate:

  • while the period has not expired, it is accepted
  • once it expires, a new one is needed

Short interview answer

Remember this formulation:

TTL in DNS is the time, in seconds, during which a DNS record can be stored in cache and used without querying the DNS server again.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.