Open In App

What is Time-To-Live (TTL)?

Time-to-live in networking refers to the time limit imposed on the data packet to be in-network before being discarded. It is an 8-bit binary value set in the header of Internet Protocol (IP) by the sending host. The purpose of a TTL is to prevent data packets from being circulated forever in the network. The maximum TTL value is 255. The value of TTL can be set from 1 to 255 by the administrators. 

The usage of TTL in computing applications lies in the performance improvement and management of data caching. It also finds its use in Content Delivery Network (CDN) caching and Domain Name System (DNS) caching.



How time-to-live (TTL) Works?

The number of hops a packet travels before being discarded by a network is known as the time to live (TTL) or hop limit. The maximum range for packets is indicated by TTL values.

Working of TTL

Thus, using the TTL value there is a restriction on the duration for which the data exists on the network. Furthermore, it also helps to find out the period of data for which it has been on the network and how long it will be on the network. 



Example:

In the scenario below, Host A wishes to interact with Host B using a ping packet. Host A uses a TTL of 255 in the ping and transmits it to Router A, its gateway. When Router A notices that the packet is going for a layer 3 i.e. Network layer, it hops to Router B, reduces the TTL by 255 – 1 = 254, and delivers it to Router B. Router B and Router C decrement the TTL in the same way. Router B decrements TTL in a packet from 254 to 253 and Router C decrements the TTL from 253 to 252. The ping packet TTL is decreased to 252 when it reaches Host B.

TTL Example

Whenever TTL reaches the value of zero, TTL=0 then the packet is discarded by the router, and the Time Exceeded Error message is sent to the originating host.

Time-to-Live (TTL) in DNS:

DNS TTL refers to the time taken by DNS for caching a record. In other words, the duration for which a DNS record is to be kept or the time it takes for a DNS record to be returned from the cache is referred to as time-to-live. It is a numerical value set in a DNS record on the domain’s authoritative domain name server.

It specifies the number of seconds for which a cache server can provide the record’s cached value. When the set time has elapsed since the previous refresh, the caching server will contact the authoritative server to obtain the current and possibly updated value for the record.

Time-to-Live (TTL) in HTTP:

TTL is measured in seconds and is set by HTTP headers such as the Cache-Control header. If the value is set to “Cache-Control: max-age=60” then it implies refreshing a given resource every 60 seconds before the time to live is surpassed. The setting “max-age=0,” implies that the resource should not be cached at all.

Time to live field has a direct impact on page load time (cached data loads faster) and content freshness on your site (i.e., data cached for too long can become stale).

TTLs should be configured as follows to ensure that your visitors only see the most recent version of your website: 

What is time-to-live  (TTL) exceeded?

IP packets delivering web HTTP traffic over TCP (Transmission Control Protocol) that have traveled too many network hops are referred to as TTL exceeded. When this situation arises then each router Each router reduces the TTL field of IP packets sent over the network until it reaches 0. The router then drops the IP packet and sends an ICMP packet with a TTL exceeded error code to the sending host.

Application of time-to-live (TTL):

The TTL value is used in the network utilities such as ping, traceroute, and pathping. 

ping command

tracert command

TTL: Time Limit or Hop Limit?

In IPv6, it is known as hop limit and in IPv4, it is known as TTL. The Hop field is same as the TTL field in IPv4.

The hop count function is necessary for network operation. It prevents networks from collapsing as a result of packets looping indefinitely. Transport protocols like TCP use the time limit function to ensure that data is transferred reliably.

Even if the elapsed time was significantly less than a second, every router that handles a packet must reduce the TTL by at least one. In this perspective, Time-to-Live serves as a hop counter. So, it puts a limit on how far a datagram can propagate via the Internet.
When a packet is forwarded, the TTL must be reduced by at least one. It may decrease the TTL by one for each second it retains a packet for longer than one second. Time-to-Live is used as a time counter in this manner.

Common TTL Values:

Normally, the TTL value is 86400 seconds or 24 hours. MX and CNAME records, on the other hand, can have a longer TTL because they are expected to change infrequently. It is recommended that you set TTL to 1 hour if your service is vital (3600 seconds). Shorter TTLs can put a strain on an authoritative name server, but they can be advantageous when changing the address of key services like web servers or MX records. As a result, DNS administrators often reduce TTLs before moving services to avoid interruptions.


Article Tags :