TTL (Time to Live)

DNS TTL (Time to Live) is a value in DNS records that tells DNS resolvers how long to cache a query result before requesting fresh data from authoritative nameservers. Measured in seconds, TTL balances the need for up-to-date information against the efficiency of caching. A longer TTL reduces server load and improves performance, while a shorter TTL ensures changes propagate more quickly.

How it works

When a DNS resolver queries an authoritative nameserver for a record, it receives not just the answer (like an IP address) but also a TTL value specifying how many seconds that answer remains valid. The resolver caches this answer and reuses it for subsequent queries until the TTL expires. Once expired, the next query forces the resolver to fetch fresh data from the authoritative server.

TTL controls the lifespan of cached DNS data: **Caching Process:** 1. **Initial Query**: A resolver queries an authoritative server for example.com and receives the IP 192.0.2.1 with a TTL of 3600 seconds (1 hour) 2. **Caching**: The resolver stores this result in its cache for 3600 seconds 3. **Cache Hits**: For the next hour, any queries for example.com are answered immediately from cache without contacting the authoritative server 4. **Expiration**: After 3600 seconds, the cached record is considered stale 5. **Refresh**: The next query after expiration forces the resolver to query the authoritative server again, potentially receiving updated information **Trade-offs:** **Long TTL (hours or days):** - ✓ Reduces load on authoritative servers - ✓ Faster DNS resolution (more cache hits) - ✓ Lower network traffic - ✗ Changes take longer to propagate - ✗ Outdated data served for longer periods **Short TTL (minutes):** - ✓ Changes propagate quickly - ✓ More up-to-date information - ✗ Higher server load - ✗ More DNS queries needed - ✗ Slightly slower resolution times

Key Points

  • TTL is always measured in seconds (e.g., 300 = 5 minutes, 86400 = 24 hours)
  • Shorter TTL values enable faster propagation of DNS changes but increase server load
  • Longer TTL values improve performance and reduce server queries but delay change propagation
  • Best practice is 1-5 days (86400-432000 seconds) for stable records
  • Lower TTL to 5-15 minutes (300-900 seconds) before making planned DNS changes

Common Use Cases

  • Stable Production Websites: Use long TTL values (24-48 hours) for established websites with infrastructure that rarely changes, minimizing DNS queries and improving performance
  • Pre-Migration Preparation: Lower TTL to 5-15 minutes a day before server migrations or DNS changes to ensure rapid propagation when changes are made
  • Development Environments: Use short TTL values (5-10 minutes) for testing and development where DNS records change frequently and quick propagation is essential
  • Load Balancing and Failover: Short TTL values allow quick updates to DNS records when servers go down or traffic needs to be redirected

code Common TTL Values

TypeHost / NameValue / Points toTTL
Value300 seconds5 minutes
Value3600 seconds1 hour
Value86400 seconds24 hours
Value172800 seconds48 hours

* TTL values are measured in seconds. Choose based on how frequently your DNS records change and how quickly you need updates to propagate.

Frequently Asked Questions

What is a good TTL value for my DNS records?expand_more
For most stable production environments, a TTL of 1-5 days (86400-432000 seconds) is recommended. This provides good performance while allowing reasonable change propagation times. Use 24 hours (86400) as a safe default. If you make frequent changes, use 1 hour (3600). For dynamic environments or development, use 5-15 minutes (300-900). The key is balancing your need for quick updates against server efficiency and performance.
Should I set TTL to 0 for instant updates?expand_more
No, never set TTL to 0. A zero or very low TTL (under 30 seconds) means resolvers must query your authoritative servers for every single request, causing massive server load and poor performance. Many DNS servers also have minimum TTL enforcement and will ignore values below their threshold (often 30-60 seconds). Instead, plan ahead by lowering TTL to 5-15 minutes before making changes, then raise it back afterward.
How do I change DNS records with minimal downtime?expand_more
Follow this process: (1) Lower your TTL to 300-900 seconds (5-15 minutes) at least 24-48 hours before the change, allowing old cached records to expire. (2) Wait for the old TTL to fully expire. (3) Make your DNS changes. (4) Wait for the new low TTL to expire so the changes propagate. (5) Raise TTL back to your normal value (e.g., 86400 seconds). This ensures changes propagate quickly while maintaining good performance afterward.
Why is my DNS change not showing up immediately?expand_more
DNS changes aren't instant because of TTL-based caching. If your record had a TTL of 86400 seconds (24 hours), anyone who queried your domain in the last 24 hours has the old value cached. They won't see the new value until their cache expires - up to 24 hours later. Additionally, some ISPs ignore TTL values and cache longer than specified. This is why lowering TTL before making changes is important - it reduces the maximum wait time for propagation.
Does TTL affect my website's speed?expand_more
Indirectly, yes. Longer TTL values improve DNS resolution speed because queries are answered from cache instead of requiring round-trips to authoritative servers. However, the difference is typically only a few milliseconds. The main performance benefit of higher TTL is reduced load on DNS servers, not end-user page load speed. Once DNS is resolved, the actual website loading speed is determined by your web server's performance, not TTL.