What is TTL?

An explanation of Time to Live (TTL) in DNS.

Deep DNS TeamOctober 23, 20257 min read

What is TTL (Time To Live) in DNS?

TTL, or Time To Live, is a crucial setting within every DNS record that dictates how long a DNS resolver is permitted to cache that record before it must query the authoritative DNS server again for fresh information. It's measured in seconds and plays a significant role in how quickly DNS changes propagate across the internet.

How TTL Works: The Caching Mechanism

Understanding the caching mechanism is key to comprehending TTL's impact.

When a DNS resolver (like your internet service provider's DNS server) looks up a domain's record, it receives the record along with its associated TTL value. The resolver then stores this record in its cache for the duration specified by the TTL. During this caching period, any subsequent requests for the same record will be served directly from the resolver's cache, without needing to contact the authoritative DNS server.

Once the TTL expires, the resolver marks the cached record as stale and will perform a new query to the authoritative DNS server the next time it receives a request for that domain. This mechanism helps to reduce the load on DNS servers and speeds up resolution times for frequently accessed domains.

DNS Record Example with TTL

Here's what a typical DNS A record looks like with TTL:

example.com.    3600    IN    A    192.0.2.1

Breaking this down:

  • example.com. - The domain name.
  • 3600 - The TTL value, in seconds (equivalent to 1 hour).
  • IN - Stands for "Internet class."
  • A - The record type (an A record for IPv4).
  • 192.0.2.1 - The IP address the domain resolves to.

Common TTL Values and Their Implications

Different use cases call for different TTL values, balancing between rapid updates and reduced server load.

# Very Short TTL (5 minutes) - Ideal for testing or during migrations
example.com.    300     IN    A    192.0.2.1

# Short TTL (15 minutes) - Suitable for frequently changing records
example.com.    900     IN    A    192.0.2.1

# Medium TTL (1 hour) - A common default for many records
example.com.    3600    IN    A    192.0.2.1

# Long TTL (24 hours) - Best for stable, rarely changing records
example.com.    86400   IN    A    192.0.2.1

Impact of TTL on DNS Changes and Propagation

The TTL value has a direct and significant impact on the speed of DNS propagation.

Shorter TTL (e.g., 300 seconds / 5 minutes)

Advantages:

  • Changes propagate quickly across the internet, minimizing downtime during updates.
  • Ideal for migrations or frequent updates where rapid changes are expected.
  • Faster recovery from mistakes as incorrect records are cached for a shorter period.

Disadvantages:

  • Increased query load on authoritative DNS servers, as resolvers request fresh data more often.
  • Slightly slower initial lookups for users, as caches expire more frequently.
  • Potentially higher bandwidth usage for DNS traffic.

Longer TTL (e.g., 86400 seconds / 24 hours)

Advantages:

  • Reduced load on authoritative DNS servers.
  • Faster DNS lookups for end users, as records are served from cache for longer.
  • Lower bandwidth costs associated with DNS queries.

Disadvantages:

  • Slower propagation of DNS changes, meaning updates take longer to become visible globally.
  • Extended downtime during migrations if not managed carefully.
  • Changes can take up to 24-48 hours to fully propagate, depending on the TTL and resolver behavior.

Best Practices for TTL Management

Important: Choosing an appropriate TTL depends on your specific needs and situation. There is no one-size-fits-all answer.

For Stable Production Environments

Use a longer TTL for records that rarely change to reduce load and improve performance.

# Production website (stable IP)
example.com.    86400   IN    A    192.0.2.1

# Mail server (stable configuration)
example.com.    86400   IN    MX   10 mail.example.com.

Before Making DNS Changes (The TTL Dance)

This is a critical strategy to minimize downtime during planned DNS changes:

  1. Step 1: Lower TTL (e.g., 24-48 hours before migration)

    example.com.    300     IN    A    192.0.2.1
    
  2. Step 2: Make the change (on migration day, after the old TTL has expired globally)

    example.com.    300     IN    A    203.0.113.1
    
  3. Step 3: Raise TTL back (after successful migration and verification)

    example.com.    86400   IN    A    203.0.113.1
    

Tip: This strategy ensures that when you make the actual change, the old TTL has already expired in most caches, allowing for much faster propagation of the new record.

For Development/Testing Environments

Use very short TTL values during active development or testing to ensure changes are reflected almost instantly.

# Development environment
dev.example.com.    60    IN    A    192.0.2.100

Checking TTL Values

You can check a domain's current TTL using command-line tools like dig or nslookup.

Using dig

dig example.com A

Output will show TTL:

example.com.    3600    IN    A    192.0.2.1
                ^^^^
                This is the TTL value in seconds

Using nslookup

nslookup example.com

Note: nslookup typically won't show the TTL by default. You might need to use verbose mode (nslookup -debug example.com) or other tools for TTL information.

Monitoring TTL Countdown

You can query the same record multiple times to see the TTL counting down in a resolver's cache:

# First query
dig example.com +noall +answer
# example.com.    3600    IN    A    192.0.2.1

# 10 seconds later
dig example.com +noall +answer
# example.com.    3590    IN    A    192.0.2.1

Note: The TTL shown in subsequent queries is the remaining cache time, not necessarily the original TTL set on the authoritative server.

TTL and Different Record Types

It's common and often beneficial for different record types to have different TTL values, depending on how frequently they are expected to change.

# Short TTL for A record (if web server IPs change often)
example.com.        300     IN    A       192.0.2.1

# Long TTL for NS records (nameservers rarely change)
example.com.        86400   IN    NS      ns1.example.com.

# Medium TTL for MX records (email server changes are less frequent than web servers)
example.com.        3600    IN    MX      10 mail.example.com.

# Short TTL for TXT record (if used for frequent verification or challenges)
example.com.        600     IN    TXT     "v=spf1 include:_spf.google.com ~all"

Common Mistakes to Avoid with TTL

Warning: These common TTL mistakes can cause significant issues and lead to unexpected downtime or propagation delays:

  • Setting TTL too high before a migration: Can cause extended downtime as old records persist in caches.
  • Setting TTL too low permanently: Increases server load unnecessarily and can slightly slow down resolution.
  • Forgetting to raise TTL after a migration: Wastes resources and can lead to unnecessary queries.
  • Not accounting for existing cache: Even after lowering TTL, old values may persist in some caches until their original TTL expires.

Advanced TTL Strategies

For complex environments or critical operations, more nuanced TTL strategies can be employed.

Progressive TTL Reduction

For critical migrations, you might reduce TTL gradually over several days to ensure maximum cache clearance.

# 1 week before migration: Set TTL to 6 hours
example.com.    21600   IN    A    192.0.2.1

# 3 days before migration: Set TTL to 1 hour
example.com.    3600    IN    A    192.0.2.1

# 1 day before migration: Set TTL to 5 minutes
example.com.    300     IN    A    192.0.2.1

# Migration day: Make the change to the new IP
example.com.    300     IN    A    203.0.113.1

Different TTL for Different Environments

Tailor TTL values to the specific needs of each environment.

# Production: Long TTL for stability and performance
www.example.com.        86400   IN    A    192.0.2.1

# Staging: Medium TTL for flexibility during testing
staging.example.com.    3600    IN    A    192.0.2.2

# Development: Short TTL for rapid iteration and immediate changes
dev.example.com.        60      IN    A    192.0.2.3

Understanding and managing TTL values is a critical aspect of effective DNS administration, allowing you to balance performance, reliability, and the speed of updates.