{
  "id": "time-to-live",
  "title": "Time to live",
  "lang": "en",
  "source_lang": "en",
  "summary": "Time to live (TTL) limits how long data remains usable or how many network hops a packet may traverse, depending on the system.",
  "category": "computer-science",
  "subcategory": "networks-security",
  "type": "concept",
  "aliases": [
    "TTL",
    "Time-to-live"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/time-to-live/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/time-to-live/",
      "json": "https://aiwiki.page/zh/time-to-live.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "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."
    },
    {
      "heading": "General principles",
      "text": "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.\n\nTwo common models are:\n\n- A decrementing counter: each qualifying operation reduces the remaining value. The object is discarded when the counter is exhausted.\n- A time-based expiration: an object becomes expired after a specified duration or at a calculated deadline.\n\nFor a simple time-based scheme, if an object receives a TTL of \\(T\\) at time \\(t_0\\), its expiration time is\n\n\\[t_{\\mathrm{expire}} = t_0 + T.\\]\n\nIts remaining lifetime at time \\(t\\) is\n\n\\[T_{\\mathrm{remaining}} = \\max(0, t_{\\mathrm{expire}} - t).\\]\n\nThese 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.\n\nA 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."
    },
    {
      "heading": "Internet packet lifetime",
      "text": "IPv4\n\nIn 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.\n\nThe 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.\n\nA 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.\n\nThe 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.\n\nIPv6\n\nInternet 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.\n\nNeither 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.\n\nError reporting and route discovery\n\nWhen 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.\n\nTraceroute 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.\n\nThe 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."
    },
    {
      "heading": "DNS record caching",
      "text": "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.\n\nFor 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.\n\nThis behavior reduces query traffic and lookup latency while allowing cached information eventually to expire.\n\nUpdates and negative answers\n\nChanging 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.\n\nConsequently, 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.\n\nDNS 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.\n\nSome 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."
    },
    {
      "heading": "Application caches and HTTP",
      "text": "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.\n\nCommon expiration policies include:\n\n- Expire after creation or writing: the lifetime begins when an entry is inserted or updated.\n- Expire after access: qualifying reads extend the lifetime, allowing frequently used entries to persist.\n- Absolute expiration: the entry expires at a fixed timestamp.\n- Refresh before expiration: the system attempts to obtain a new value while the existing value remains usable.\n\nThese policies are not interchangeable. A read that renews one cache entry’s lifetime may have no effect in another system.\n\nHTTP freshness\n\nHTTP 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.\n\nA 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.\n\nThe 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."
    },
    {
      "heading": "Databases, messages, and distributed state",
      "text": "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.\n\nImportant implementation distinctions include:\n\n- whether expired data becomes immediately invisible to reads;\n- whether physical removal occurs synchronously or later;\n- whether updates preserve, remove, or renew an expiration time;\n- how expiration interacts with replication and recovery.\n\nMessaging 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.\n\nIn 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."
    },
    {
      "heading": "Trade-offs and limitations",
      "text": "Freshness and availability\n\nShort 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.\n\nTTL-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.\n\nRefresh bursts and timing\n\nIf 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.\n\nTimekeeping 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.\n\nSecurity and deletion\n\nPacket 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.\n\nTTL 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."
    }
  ],
  "links": [
    "internet",
    "domain-name-system",
    "router",
    "operating-system",
    "load-balancing",
    "application-programming-interface",
    "hypertext-transfer-protocol",
    "database",
    "redis",
    "database-replication",
    "distributed-computing",
    "distributed-consensus",
    "cache-coherence",
    "eventual-consistency",
    "authentication",
    "encryption",
    "data-backup"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}