Time to live (TTL) is a value that limits the lifetime or continued use of data in a computing system. In Internet networking, it limits how far a packet can travel before being discarded. In the Domain Name System (DNS), caches, and databases, it usually specifies a duration after which stored information expires or requires renewed validation. Despite the shared name, these mechanisms have different units and enforcement rules: a network TTL commonly counts forwarding hops, while a cache TTL commonly measures elapsed time.
General principles
A TTL attaches a bounded lifetime to an object, such as a packet, cached answer, database record, or message. Its interpretation depends on the protocol or application.
Two common models are:
- A decrementing counter: each qualifying operation reduces the remaining value. The object is discarded when the counter is exhausted.
- A time-based expiration: an object becomes expired after a specified duration or at a calculated deadline.
For a simple time-based scheme, if an object receives a TTL of at time , its expiration time is
Its remaining lifetime at time is
These equations do not determine what happens after expiration. A system may reject the object, refresh it, mark it as stale, or schedule it for later removal. Expiration and physical deletion are therefore separate events.
A TTL also differs from a timeout. A timeout normally limits how long an operation may wait or execute; a TTL normally limits the lifetime or validity of an object.
Internet packet lifetime
IPv4
In Internet Protocol version 4 (IPv4), TTL is an 8-bit field in the packet header, with representable values from 0 to 255. It prevents packets from circulating indefinitely, particularly when routing errors create loops.
The original IPv4 specification, published in 1981, defined TTL in seconds and required each module processing the packet to reduce it by at least one, even when processing took less than a second. In ordinary forwarding, TTL consequently functions primarily as a hop limit rather than a precise elapsed-time measurement.
A forwarding router reduces the TTL by at least one. If the value is exhausted, the router discards the packet rather than forwarding it. Thus, a packet arriving at a router with TTL 1 normally cannot pass through that router.
The sender selects the initial value, often through an operating system default. Values such as 64, 128, and 255 are common, but no single value applies to all hosts. The remaining TTL observed at a destination does not reveal the exact number of routers traversed unless the initial value is known.
IPv6
Internet Protocol version 6 (IPv6) replaces the IPv4 field name with Hop Limit, making its practical meaning explicit. This is also an 8-bit field. Each forwarding node decrements it by one, and a packet cannot be forwarded when the limit is exhausted.
Neither field is a limit on a complete connection. A long-lived TCP connection can exchange many packets, each with its own initial TTL or Hop Limit.
Error reporting and route discovery
When a router discards a packet because its lifetime has expired, it generally sends a Time Exceeded message using the Internet Control Message Protocol (ICMP), subject to rules that suppress certain error messages and to implementation rate limits.
Traceroute uses this behavior to investigate network paths. It sends probes with successively larger TTL or Hop Limit values. The first forwarding router may report expiration for a probe with a value of 1, the second for a value of 2, and so on.
The results are not necessarily a complete or stable map. Routers may suppress replies, return paths can differ from outgoing paths, and load balancing may send different probes over different routes. A missing reply does not by itself demonstrate that a router failed to forward ordinary traffic.
DNS record caching
DNS uses TTL to control how long a resource record may remain reusable in a cache without obtaining a fresh answer. DNS TTL values are expressed in seconds and accompany resource records.
For example, a resolver that receives an address record with a TTL of 3,600 seconds can normally reuse it for up to one hour. If it answers another client after ten minutes, it ordinarily supplies the remaining lifetime rather than restarting the original hour.
This behavior reduces query traffic and lookup latency while allowing cached information eventually to expire.
Updates and negative answers
Changing a record at an authoritative DNS server does not immediately invalidate copies already held by resolvers. Those copies can remain usable until their existing TTLs expire. Lowering the authoritative TTL also does not retroactively shorten TTLs already cached.
Consequently, a DNS change does not have a single universal “propagation time.” Observed results depend on when caches obtained their answers, their remaining lifetimes, authoritative server updates, and implementation behavior.
DNS also supports negative caching: caching information that a queried name or record type does not exist. The lifetime of a negative answer is derived from information in the zone’s start-of-authority record under DNS negative-caching rules.
Some resolvers implement standardized serve-stale behavior, allowing expired information to be returned under specified conditions, such as difficulty reaching authoritative servers. Thus, normal TTL expiration and an absolute prohibition on serving an old answer are not identical.
Application caches and HTTP
Application caches use TTLs to trade freshness against the cost of retrieving or recomputing data. Cached results may include database queries, rendered pages, service-discovery information, or responses from an application programming interface.
Common expiration policies include:
- Expire after creation or writing: the lifetime begins when an entry is inserted or updated.
- Expire after access: qualifying reads extend the lifetime, allowing frequently used entries to persist.
- Absolute expiration: the entry expires at a fixed timestamp.
- Refresh before expiration: the system attempts to obtain a new value while the existing value remains usable.
These policies are not interchangeable. A read that renews one cache entry’s lifetime may have no effect in another system.
HTTP freshness
HTTP expresses cache freshness through mechanisms including the Cache-Control: max-age directive and the Expires header. These serve a role similar to TTL, but HTTP also defines response-age calculations, validation, and rules for shared and private caches.
A stale response is not necessarily deleted. A cache may contact the origin server to validate it and then reuse the stored representation if it remains unchanged.
The directives no-cache and no-store have distinct meanings: no-cache generally requires validation before reuse, whereas no-store directs a cache not to store the response. Neither is simply another name for a zero TTL.
Databases, messages, and distributed state
A database may support TTL-based expiration for individual records, keys, or collections. Redis, for example, supports expiration times on keys. Other systems use background processes that identify and remove expired records periodically.
Important implementation distinctions include:
- whether expired data becomes immediately invisible to reads;
- whether physical removal occurs synchronously or later;
- whether updates preserve, remove, or renew an expiration time;
- how expiration interacts with replication and recovery.
Messaging systems may similarly attach TTLs to messages so that outdated work is discarded instead of delivered. The lifetime may be measured from creation, publication, or entry into a particular queue, depending on the system.
In distributed computing, TTLs also appear in temporary registrations and leases. However, a TTL alone does not establish exclusive ownership or provide distributed consensus. Delayed messages, process pauses, and uncertain clock behavior can allow an old participant to act after another participant considers its lease expired. Such systems may require additional mechanisms, including monotonically increasing fencing tokens that reject obsolete operations.
Trade-offs and limitations
Freshness and availability
Short TTLs generally reduce the normal lifetime of stale cached data but increase refresh traffic and dependence on upstream services. Long TTLs reduce repeated work and may help sustain service during temporary upstream failures, but can preserve outdated information longer.
TTL-based expiration is not equivalent to cache coherence. An entry can become outdated immediately after it is cached and remain usable until expiration unless another mechanism invalidates it. Nor does a TTL alone guarantee eventual consistency: successful refreshes and the wider update protocol also matter.
Refresh bursts and timing
If many entries expire simultaneously, requests may converge on an underlying service, producing a cache stampede. Systems may reduce this effect through staggered expiration times, coordinated refreshes, or probabilistic early refresh.
Timekeeping also matters. Wall clocks can move because of administrative changes or clock synchronization. Local elapsed-time measurements often use a monotonic clock, while deadlines exchanged between machines require explicit assumptions about clock differences and delays.
Security and deletion
Packet TTL bounds forwarding lifetime but does not provide authentication or encryption. Cache TTLs likewise limit ordinary reuse without proving that the cached information is authentic or correct.
TTL expiration is also not a guarantee of secure erasure or compliance with a data-retention requirement. Expired information may remain in logs, replicas, backups, or storage awaiting reclamation. Systems that require deletion must define those obligations separately from ordinary expiration.