Sub topic 7
How TTL limits a packet's lifetime
This chapter assumes you know what an IP address is, can open a command prompt or terminal, and understand that routers forward packets between networks. It also assumes you have seen basic ping output. Here you learn what the TTL field is, how routers change it, and why ICMP Time Exceeded messages are the basis of traceroute.
What TTL is and why it exists
Every IPv4 packet carries a one-byte header field called TTL (time to live). In IPv6 the same field is called the hop limit. Its job is to stop a packet from circulating forever.
Routing mistakes can create loops, where router A sends a packet to B and B sends it back to A. Without a limit, looping packets would pile up and use all the bandwidth. TTL puts a hard cap on how many routers a packet can pass through.
Despite the name, TTL is not measured in seconds. It is a hop counter. Each router that forwards the packet is one hop.
The rules every router follows
- The sender sets an initial TTL. Common defaults are 64 (Linux and macOS), 128 (Windows), and 255 (many network devices).
- Each router that forwards the packet subtracts 1 from the TTL.
- If the TTL reaches 0, the router discards the packet. It does not forward it.
- The router that discards the packet sends an ICMP Time Exceeded message (type 11 in ICMPv4) back to the original sender. The message's source address is the discarding router's own address.
Step 4 is the important one. The sender learns that its packet died, and it learns which router killed it.
Seeing TTL in ping output
Each ping reply shows the TTL of the reply packet as it arrived. On Windows it looks like this:
Reply from 8.8.8.8: bytes=32 time=14ms TTL=117The value is the TTL left after the reply crossed the network. If you assume the remote host started at 128 (or 64, or 255, whichever default is nearest above the value), you can estimate the hop count. A TTL of 117 suggests a start of 128 and about 11 hops on the return path.
This is only an estimate. Hosts can use any starting value, and the return path may differ from the outgoing path.
Making TTL visible
You can set the starting TTL yourself and watch the packet die. On Windows, -i sets the TTL for ping:
ping -n 1 -i 1 example.comIf a router sits between you and the destination, the reply looks like this:
Reply from 192.168.1.1: TTL expired in transit.The address shown is the first router, which received a packet with TTL 1, reduced it to 0, and dropped it. Raising -i to 2 would make the second router answer, and so on. The next chapters show how tracert and traceroute automate exactly this.
On Linux, the equivalent option is -t:
ping -c 1 -t 1 example.comOn macOS, use -m instead of -t.
Why this matters for traceroute
traceroute sends probes with TTL 1, then 2, then 3, and so on. Each probe expires one hop further along the path. Each expiry produces a Time Exceeded message from a different router, so the list of senders of those messages is the list of routers on the path. When a probe finally reaches the destination, the destination replies normally and the trace ends.
Common errors
- Reading TTL as seconds. It counts hops, not time.
- Treating the TTL in a reply as the remote host's default. It is the value after decrementing along the return path.
- Expecting every router to answer. Some routers drop expired packets without sending Time Exceeded. These appear as gaps in a trace, which a later chapter covers.
Exercise
You run a ping and the reply shows TTL=52. Assuming the remote host started at 64, roughly how many hops did the reply cross, and why is this only an estimate?
Show answer
About 12 hops (64 − 52). It is an estimate because the host may have used a different starting TTL, and the return path may differ in length from the outgoing path.
Exercise
A packet leaves your computer with TTL 3. Which router discards it, and what does that router send back?
Show answer
The third router on the path. It reduces the TTL to 0, drops the packet, and sends an ICMP Time Exceeded message to your computer.