Back to all questions

How Does a Traceroute Work?

Michael Hakimi
Network Analytics
November 13, 2024

Traceroute is a network diagnostic tool that tracks the path data takes from your device to a target server. It maps each "hop" along the way, revealing the journey your data takes through routers and networks. This helps you identify where slowdowns or failures happen.

If you’ve ever wondered what’s really going on between you and the server you’re trying to reach, traceroute is the tool that gives you an under-the-hood view of your data's journey. 

What Traceroute Does

Traceroute tracks the path that data packets take through a network to reach their destination. Imagine sending a letter across a city. You drop it at the post office, and it passes through multiple checkpoints before reaching its final address. 

Each checkpoint might represent a router, server, or another network node. Similarly, traceroute maps each "hop" a data packet takes across routers, so you can see the exact path and measure the time it takes to go from one point to the next.

The purpose? Simple: It helps you figure out where any slowdowns, disruptions, or failures are happening on that path. 

How Traceroute Works

To explain how a traceroute works, we’ve got to talk about a few key components:

  1. ICMP Packets (or UDP/ICMP Echo Requests): Traceroute uses a special kind of message known as an ICMP Echo Request (on most systems). Some systems use UDP packets, but the idea is essentially the same. Each packet you send out contains an identifier that says, "Hey, tell me how far along the path I got!"
  2. Time-to-Live (TTL): This is where the magic happens. Each data packet that traceroute sends out comes with a "Time-to-Live" (TTL) value. This TTL value controls how far the packet can travel before it gets discarded. Each router on the path will reduce this TTL by one, so if a packet reaches a router and the TTL hits zero, that router sends back a message saying, "I’m as far as this packet got."
  3. Incrementing TTL: Here’s the trick: the first packet traceroute sends has a TTL of 1. So it’ll only make it to the first router, which sends back a message saying, “I’m router 1!” Traceroute then sends another packet with a TTL of 2. Now, the packet makes it to the second router before being discarded, and so on. This process continues until the packet reaches the final destination.
  4. Round-Trip Time (RTT): For each hop, traceroute records how long the round-trip time (RTT) takes for the packet to go from your device to the router and back. These times, measured in milliseconds (ms), help you identify latency or slowdowns between specific points in the journey.

What Happens During a Traceroute?

Let’s walk through what happens, step by step, when you run a traceroute.

  1. First packet is sent with TTL=1 – The packet reaches the first router in the chain. The router decreases the TTL to 0 and says, "This is as far as I got," sending a message back to you. You now know the identity and location of Router 1.
  2. Next packet is sent with TTL=2 – This packet reaches Router 2 before the TTL is exhausted. It sends a similar message back, telling you about its identity and location.
  3. Repeat – Traceroute continues to send packets, incrementing the TTL until one of two things happen:some text
    • The packet reaches the destination (and the final hop sends an acknowledgment back).
    • The packet hits a router or firewall that blocks it, causing the traceroute to time out.

At the end, you’ll have a full list of routers and devices the packet passed through, as well as the time it took to traverse each hop.

Technical Details and Protocols

Here’s where it gets technical—and it’s important to know this if you’re really digging into how traceroute works. Traceroute can use different protocols to send its packets, depending on the operating system:

  • ICMP (Internet Control Message Protocol): This is what most Windows systems use for traceroute. It’s the same protocol used by ping.
  • UDP (User Datagram Protocol): Many Linux systems use UDP packets, specifically aimed at high-numbered ports that usually don’t have a service listening.
  • TCP (Transmission Control Protocol): Some modern implementations of traceroute will use TCP packets to bypass firewalls, which might block ICMP or UDP traffic but allow TCP packets to go through.

The good news is, as a user, you typically don’t have to worry about which protocol is being used, but understanding them can help if you’re troubleshooting firewall issues or network-specific problems.

Web Traceroute vs Command-Line Traceroute

Most of the time, when people talk about traceroute, they’re referring to the traceroute tool you run in your terminal or command line (on Windows, it’s called tracert). However, there are also web-based traceroute tools. These tools let you run a traceroute from an online interface rather than your local machine.

What’s the difference? When you run traceroute from your computer, it tracks the path between you and the destination server. But with a web traceroute, the path is traced from the server that’s hosting the web tool to the target; you could measure technicals like the average latency of a CDN.

It’s a great way to get a different perspective on the network path, especially if you suspect that your local network might be causing issues. Both methods work similarly, but they give you a slightly different view of the path, depending on where the traceroute originates.

Interpreting Traceroute Results

When you look at traceroute results, you’ll see a few key pieces of information:

  • Hop Number: The sequence of routers the packet traveled through.
  • Router Address: The IP address (or sometimes the hostname) of each router.
  • RTT (Round-Trip Time): The time it took for the packet to travel to the router and back, typically listed in milliseconds for each hop.

Occasionally, you’ll see an asterisk (*) in the traceroute output. This usually means that the packet hit a firewall, or the router didn’t respond in time. Multiple asterisks in a row could indicate a network issue or a router blocking ICMP/UDP packets altogether.

Why Traceroute is Useful

Traceroute is a tool I often lean on when I need to figure out where the problem is in a network. For example, if a website is loading slowly, I can run a traceroute and see if a specific hop is adding delay. Maybe it’s a congested router or a misconfigured firewall.

Without traceroute, I’d just be guessing. But by mapping out the network path, I can pinpoint exactly where things start to slow down and take appropriate action.

Sometimes, traceroute can also reveal things like:

  • Routing Loops: Where data gets stuck bouncing between the same routers.
  • Failed Hops: Where a router is down or unreachable.
  • Latency Issues: If one hop has much higher RTT times than the others, it could be causing the delay.