Time to Live (TTL) is a technical setting that limits how long data remains in a network or cache before being discarded or refreshed. In networking, it prevents data from circulating indefinitely, while in SEO and web performance, it controls how long servers cache your content.
Understanding TTL helps you manage site speed, ensure users see the latest updates, and reduce server load during traffic spikes.
What is TTL?
TTL acts as a self destruct time limit for data. It can be implemented as a counter or a timestamp. Once the prescribed count or time has passed, the data is either deleted or revalidated.
In the context of the Internet Protocol (IP), [TTL is an 8-bit field within the data header] (Wikipedia). This means the [maximum possible TTL value is 255] (Wikipedia).
While TTL usually refers to data expiration, the acronym is also used by Turntable Lab (TTL), a Brooklyn based online store established in 1999 that specializes in vinyl records and audio gear.
Why TTL matters
TTL settings directly impact how users interact with your website and how your infrastructure handles traffic.
- Content Freshness: Lower TTLs ensure users see new product descriptions or price changes faster.
- Server Efficiency: Higher TTLs allow your server to rest by serving cached content rather than processing new requests.
- Site Reliability: During migrations or server changes, lowering TTL helps prevent downtime by making the new DNS records propagate quickly.
- User Experience: Caching stored in a layer close to the user enables large, content-heavy sites to load much faster.
How TTL works
The mechanism differs slightly between network packets and web caching.
Networking (Hops)
When an information packet moves across the internet, it passes through various routers. 1. The sender sets an initial TTL value. 2. [The current recommended default value for IP is 64] (Wikipedia). 3. Every router that receives the packet subtracts one from the TTL count. 4. If the count reaches zero, the router discards the packet and sends an ICMP error message back to the sender.
DNS and CDN Caching
In caching, TTL is measured in seconds rather than hops. 1. An authoritative nameserver sets a TTL for a DNS record. 2. A caching server (like a CDN) stores that record for the specified time. 3. If a user requests the record before the TTL expires, the server provides the cached copy. 4. Once the time expires, the server must fetch a fresh copy from the origin.
Best practices
Lower TTL before site migrations. Reduce your TTL settings at least 24 hours before moving to a new server. This ensures that the change to your new IP address is recognized by DNS servers worldwide within minutes rather than days. [A 300-second TTL can help key records expire in 5 minutes] (Wikipedia).
Balance TTL based on update frequency. If your site uses an interactive API or frequently updates stock, use a lower TTL. An example company, ABC Widgets, might use a [3,600-second (one hour) TTL] (Fortinet) normally, but reduce it during busy sales seasons to show accurate inventory.
Use higher TTL for static assets. For images, CSS, and hardware descriptions that rarely change, set a higher TTL. This reduces the bandwidth required from your origin server.
Audit your DNS records regularly. Check your SOA (Start of Authority) records. [TTL for non-existent domain (NXDOMAIN) responses is set based on the minimum of the SOA's MINIMUM field and the TTL of the SOA itself] (Wikipedia).
Common mistakes
Mistake: Forgetting to raise TTL after a migration. Fix: Once a move is stable, increase the TTL back to a standard value (like 86400 seconds) to reduce the load on your authoritative nameserver.
Mistake: Assuming TTL guarantees worldwide updates. Fix: Be aware that some caching nameservers ignore authoritative TTLs and set their own limits, meaning some users may still see old data after your TTL expires.
Mistake: Setting an extremely low TTL for no reason. Fix: Only use very low TTLs (under 60 seconds) for highly dynamic content. Otherwise, you may overwhelm your nameserver with unnecessary queries.
TTL vs Hop Limit
While these terms are often used interchangeably, they refer to specific protocol versions.
| Feature | IPv4 TTL | IPv6 Hop Limit |
|---|---|---|
| Unit | Seconds (in theory), Hops (in practice) | Hops |
| Header Position | [9th octet of 20] (Wikipedia) | [8th octet of 40] (Wikipedia) |
| Action | Decrements by 1 at each router | Decrements by 1 at each router |
FAQ
What is a standard TTL value for DNS? [A common older value was 86400 seconds, which equals 24 hours] (Wikipedia). Many modern set-ups use shorter periods, such as 3,600 seconds (1 hour), to allow for more flexibility.
How does traceroute use TTL? The traceroute command sends a stream of packets with increasingly higher sequential TTLs. Each router along the path becomes the last stop for one of these packets. When the router discards the packet at TTL zero, it returns an ICMP message, allowing the command to identify every hop in the network chain.
Can TTL improve website speed? Yes. By caching content in a CDN with an appropriate TTL, you serve data from an edge server closer to the user. This reduces the time it takes for a browser to retrieve the site compared to fetching it from a distant origin server every time.
What happens when a TTL expires in a CDN? When the TTL reaches zero, the CDN edge server considers the content "stale." The next time a user requests that content, the CDN reaches out to the origin server to get a new copy and resets the TTL clock.
Can I set different TTLs for different records? Yes. TTL values are set per record. You might have a high TTL for your MX (email) records but a very low TTL for a specific API endpoint that updates frequently.