Sub topic 7
How TTL limits a packet's lifetime
This chapter assumes you know what an IP address is, that packets cross routers to reach other networks, and that ping sends ICMP echo requests. You will learn what the Time to Live (TTL) field does, why it exists, how routers handle it, and how it explains both ping's TTL value and the way traceroute works.
The problem TTL solves
IP routers forward packets using routing tables. Routing tables can be wrong. During a misconfiguration or while routes are changing, two routers can each believe the other is the next hop toward a destination. A packet sent into that loop would bounce between them forever, using bandwidth on every pass.
IP prevents this with a counter in the packet header. The field is called TTL (Time to Live) in IPv4. In IPv6 it is called Hop Limit, and it works the same way. The field is 8 bits wide, so its value ranges from 0 to 255.
The rules are simple:
- The sender sets the initial TTL.
- Each router that forwards the packet subtracts 1.
- If the value reaches 0, the router discards the packet instead of forwarding it.
- The router that discards it normally sends an ICMP Time Exceeded message back to the original sender.
The name "Time to Live" is historical. The original design described a number of seconds. In practice, every router counts one hop, so the field behaves as a hop counter.
A packet crossing routers
The diagram shows a packet that starts with TTL 3 and is dropped at the third router.
Two details matter here:
- The router that drops the packet is the one that reports. Routers 1 and 2 forwarded the packet normally and said nothing.
- The Time Exceeded message carries the router's own source address. That is how the sender learns who the router is.
Where ICMP Time Exceeded fits
ICMP Time Exceeded is ICMP type 11 for IPv4 (code 0 means "TTL exceeded in transit"). ICMPv6 uses type 3 for the same purpose. The message includes the IP header and the first bytes of the discarded packet. This lets the sender match the error to the packet that caused it.
In the ping output on Windows, you may see this message when a packet dies in transit:
Reply from 203.0.113.9: TTL expired in transit.The address in that line is the router that discarded the packet. It is not the destination. This is a useful clue: if you see this for a normal ping, the TTL was too small to reach the destination, or a routing loop is consuming the packet.
Initial TTL values differ by operating system
The sender chooses the starting TTL, and operating systems pick different defaults. Common defaults are:
| Operating system family | Typical default TTL |
|---|---|
| Windows | 128 |
| Linux and macOS | 64 |
| Many network devices | 255 |
These are conventions, not guarantees. Administrators can change them, and some devices use other values.
Reading TTL in a ping reply
The TTL printed in a ping reply is the value in the reply packet when it arrived at your machine. It is not the TTL of your request. It is the remote host's starting TTL minus the number of routers the reply crossed on the way back.
For example, suppose you see this:
Reply from 8.8.8.8: bytes=32 time=14ms TTL=115Remote systems commonly start at 64, 128, or 255. Because 115 is below 128 and above 64, the starting value was probably 128. That means the reply crossed about 13 routers. The result is an estimate, because you are guessing the starting value, and the return path may differ from the outbound path.
A reply from a machine on your own subnet usually shows the starting value unchanged, for example TTL=128 from a Windows host or TTL=64 from a Linux host, because no router decrements it. This is why pinging your own address or a neighbour shows a high value, and a distant server shows a lower one.
Setting TTL yourself with ping
You can set the starting TTL in your own request and watch what happens. On Windows, -i sets the TTL. On Linux, -t sets it. On macOS, -m sets it.
ping -n 1 -i 2 example.comWith TTL 2, the request can pass at most one router before the second router discards it. You typically get a reply of this form:
Reply from 198.51.100.1: TTL expired in transit.The address belongs to the router that dropped your request. This is the central observation behind traceroute. Run the same test on Linux:
ping -c 1 -t 2 example.comIf you raise the number one step at a time, you will eventually pick a TTL large enough to reach the destination, and then you get a normal echo reply.
How TTL powers traceroute
Traceroute turns the TTL rule into a measuring tool. It does not need any special support from routers. It uses the Time Exceeded message that routers already send.
The procedure is:
- Send a probe with TTL 1. The first router decrements it to 0, drops it, and returns Time Exceeded. Its source address identifies hop 1.
- Send a probe with TTL 2. The second router returns Time Exceeded. That identifies hop 2.
- Increase the TTL by one each round.
- Stop when the destination itself answers, or when a maximum hop count is reached.
The time between sending a probe and receiving the reply gives the round-trip time to that hop.
Windows tracert sends ICMP echo requests as probes. Linux and macOS traceroute sends UDP datagrams to high port numbers by default. The destination answers those with an ICMP Port Unreachable message. The -I option switches to ICMP echo probes. In all cases, intermediate routers answer with Time Exceeded, and the final answer comes from the destination.
Practical limits and edge cases
TTL behaviour has several gotchas that affect how you read results.
- Hop count is not distance. One hop can be a short link in the same building or a long-haul link across an ocean. Compare latency, not just hop numbers.
- Paths can change between probes. Load balancing can send consecutive probes along different routes. A traceroute may list routers that never appear together in a single real path.
- The return path can differ. Traffic often returns by a different route than it went out. The times reported for a hop include the return trip from that router, which may take an unrelated path.
- Some routers do not reply. A router that is configured to ignore expired packets, or that rate-limits its ICMP responses, appears as asterisks in traceroute output. Traffic still passes through it normally.
- Some devices do not decrement TTL. Layer 2 switches and many bridges forward frames without touching the IP header, so they never appear as hops.
- Tunnels hide hops. A VPN or tunnel carries the original packet inside another packet. Routers inside the tunnel decrement the outer TTL, so you might see only the tunnel endpoints.
- Maximum hops can be too low. If the destination is further than the cap, the trace stops early. Use
-hontracertor-montracerouteto raise the limit. - A very small TTL fails by design. A TTL of 0 sent by a host never leaves the host, and a TTL of 1 never leaves the local network.
Worked example
Suppose tracert -d example.com prints this partial output:
1 <1 ms <1 ms <1 ms 192.168.1.1
2 9 ms 8 ms 9 ms 10.20.0.1
3 11 ms 10 ms 10 ms 203.0.113.5
4 * * * Request timed out.
5 24 ms 25 ms 24 ms 198.51.100.77Applying what you know about TTL:
- Probes with TTL 1, 2, and 3 expired at three routers, which each replied, so those hops are identified.
- Probes with TTL 4 passed the third router and expired at the fourth, but no Time Exceeded message came back. Router 4 may be filtering or rate-limiting ICMP.
- Probes with TTL 5 got through that same router. If it had dropped transit traffic, hop 5 could not answer. So hop 4 is silent, but it is forwarding.
This is the key inference: a silent hop followed by working hops is not a fault. A real break shows asterisks on every hop from some point to the end.
Exercise
A Windows host pings a server and gets TTL=118 in the reply. Estimate the server's starting TTL and the number of routers the reply crossed. Then explain why you are not certain.
Show answer
The common starting values are 64, 128, and 255. The nearest one above 118 is 128, so the starting TTL was probably 128 and the reply crossed about 10 routers (128 - 118). The estimate is uncertain because the starting TTL is only a guess based on common defaults, the administrator may have changed it, and the return path can differ from the path your request took.
Exercise
You run ping -n 1 -i 3 example.com and receive "Reply from 203.0.113.5: TTL expired in transit." What does the address 203.0.113.5 represent, and what would you change to reach the destination?
Show answer
The address is the router that decremented the TTL to 0 and discarded the packet, which is the third router on the path. To reach the destination, raise the TTL with -i until an ordinary echo reply arrives, or omit -i to use the default value.