TTL and Hop Limits: How Packets Avoid Looping Forever
Find out how a small counter in every IP packet stops routing loops, powers traceroute and can even act as a simple safety check.
Key takeaways
- The counter is eight bits, so no packet can cross more than 255 routers.
- Routers decrement it, and a router that cannot forward because it ran out sends back an ICMP "time exceeded" message.
- Different operating systems start with different values, commonly 64 or 128.
- Traceroute works by sending packets with deliberately small values.
- IP TTL counts hops and has nothing to do with DNS caching time, despite sharing a name.
Every IP packet carries a small counter. Each router that forwards the packet lowers it by one, and when it reaches zero the packet is thrown away. In IPv4 the field is called Time To Live (TTL). In IPv6 it is called Hop Limit, which describes what it really does.
Without it, a packet caught between two routers that each think the other is the way forward would circle until the equipment drowned in its own traffic. With it, the damage is bounded.
What a routing loop is
Routers decide where to send each packet by consulting their own tables. Those tables are built independently, and for brief moments or because of mistakes they can disagree.
Say router A believes the path to 198.51.100.0/24 goes through router B, while B believes it goes through A. A packet for that network bounces between them. This can happen during convergence after a link failure, when static routes point at each other, or when a router summarizes a block it only partly knows how to reach and has a default route back to its neighbor.
How routers decide where to send a packet covers the tables themselves. The counter is the backstop for when they are wrong.
How the countdown works
The sender sets the initial value. Each router that forwards the packet subtracts one before sending it on. If the result would be zero, the router discards the packet and normally returns an ICMP Time Exceeded message to the source address.
In ICMP for IPv4 the message is type 11, and the code for expiry in transit is 0. In ICMPv6 it is type 3, code 0.
The IPv4 specification originally allowed the field to measure seconds, with each device subtracting at least one. In practice it became a pure hop count. Because the IPv4 header has its own checksum, each router also updates that checksum after changing the TTL. IPv6 dropped the header checksum, which removes that step.
The counter only changes at devices that route. Ordinary Ethernet switches forward frames without touching the IP header, so five switches in a row are invisible to it. It also means the Ethernet layer has no equivalent protection: a loop between switches is stopped by protocols such as Spanning Tree, and if those fail, frames really can circulate indefinitely.
Some tunnels and provider core networks carry packets inside another layer, so several physical routers may appear as a single hop.
Starting values
A sender chooses how far its packets may travel. Common defaults are:
| Starting value | Often seen on |
|---|---|
| 64 | Linux, macOS, Android, iOS and many embedded devices |
| 128 | Windows |
| 255 | Some network equipment and certain protocols |
Typical internet paths are far shorter than 64 hops, so these defaults leave plenty of margin.
When you ping a host, the reply shows the TTL left on arrival. A value of 117, for instance, suggests a start of 128 and about 11 routers between you. Treat this as a hint only: administrators can change defaults, middle devices can rewrite the field, and the return path may differ from the outbound one.
How traceroute turns expiry into a map
Expiry messages come from the router where the packet died, and they reveal that router's address. Traceroute exploits this. It sends a probe with TTL 1, which dies at the first router. Then TTL 2, which dies at the second, and so on until a reply comes from the destination.
Some routers send no expiry message or rate-limit them, which shows up as asterisks. How to use traceroute explains how to read the output without jumping to wrong conclusions.
You can experiment with the counter directly. The flag differs by system.
Windows: ping -i 3 example.com
Linux: ping -t 3 example.com
macOS: ping -m 3 example.com If the destination is more than three routers away, you should see time-exceeded responses from an intermediate router, or silence if it doesn't send them.
Using the counter as a safety check
Because routers always decrease the value and never raise it, a receiver can use it to judge distance.
The Generalized TTL Security Mechanism (RFC 5082) has directly connected BGP neighbors send packets with TTL 255 and reject anything that arrives lower. A packet from several hops away cannot arrive with 255, so remote forgeries are discarded cheaply.
IPv6 Neighbor Discovery, which finds other devices on a link, requires a hop limit of 255 for the same reason: it proves the message didn't cross a router. Neighbor Discovery relies on this check.
Senders can also use a small value to keep traffic close. Multicast applications often limit it to 1 so packets stay on the local network, and many local discovery protocols use addresses that routers are not allowed to forward at all.
Not the same as DNS TTL
DNS records also have a TTL, and the two are unrelated. A DNS TTL is a number of seconds that resolvers may keep an answer in cache. It affects how quickly a change is noticed, as explained in DNS caching and TTL.
An IP TTL lives in the packet header and counts hops. HTTP caches use similar language too. When someone says "lower the TTL", ask which one.
Recognizing expiry problems
The usual message is "TTL expired in transit" on Windows, or "Time to live exceeded" on Linux and macOS.
- Run a traceroute. If two addresses alternate over and over until the maximum hop count, you are looking at a loop.
- Find who owns the looping routers. If they are yours, inspect the routes for that destination on both. Look for static routes pointing at each other, or a summary route with no discard route behind it.
- If they belong to your provider, send them the destination, time and trace output.
- If there is no loop but packets still expire, look for a sender with an unusually low TTL or a device rewriting it.
Preventing loops is better than absorbing them. When you advertise a summary, add a matching route that discards traffic for parts of the block you don't use. A summarized network without that safeguard can bounce unused addresses between itself and its upstream until each packet runs out.
Seeing the value on the wire
You can watch the counter without special equipment. Ping prints it for each reply:
Reply from 192.0.2.10: bytes=32 time=14ms TTL=117 On Linux and macOS the label is lowercase ttl=, and over IPv6 some tools show hlim= or still call it ttl.
If you capture traffic with Wireshark, the IPv4 header shows "Time to Live" and the IPv6 header shows "Hop Limit". A few things are worth noticing:
- Packets your own machine sends carry its starting value, unchanged.
- Packets from your router's local address typically arrive with the router's starting value, because no router sits between you.
- Packets from distant servers arrive reduced, by the length of the return path.
- A sudden change in the arriving value from one server usually means the route changed, or that a different machine is now answering.
That last point is occasionally useful in troubleshooting. If a reply that normally arrives with one value suddenly arrives with a much higher one, something closer to you may be answering on the server's behalf, such as a captive portal, a filtering device or a proxy. It is a reason to look further, not proof by itself.
Where the setting can be changed
Most people never need to change the default. Operating systems do let administrators do it: Linux has a kernel setting named net.ipv4.ip_default_ttl, which you can read with:
sysctl net.ipv4.ip_default_ttl IPv6 hop limits on a local network are normally suggested by the router in its advertisements, and hosts adopt that value. Application developers can set a per-socket value, which multicast software does routinely.
Lowering the system default far below the standard values is a good way to create baffling failures, where nearby sites work and distant ones don't. If you inherit a machine with that symptom, check this setting along with more common culprits. Raising it buys nothing, since healthy internet paths already fit comfortably.
What the counter doesn't do
The hop limit only stops each packet eventually. It doesn't fix the loop, and during one, every packet is carried across the same link many times, multiplying load. A modest stream to a looping destination can fill a link before individual packets expire.
It also isn't a security boundary on its own, apart from careful uses like the 255 check. Anyone can choose their starting value. Think of it as a circuit breaker built into every packet: simple, universal and enough to keep a routing mistake from lasting forever in the wires.