Find a course

Module 3: Moving Data: Transport and RoutingLesson 8 of 1311 min

Routing, Gateways and TTL

Learn how hosts decide between local and remote delivery, how routers read routing tables and pick the most specific route, and how TTL and traceroute work.

Step 1 of 13Learn

Hop by hop across the internet

No router on the internet knows the full path from your laptop to a server in Tokyo. Each one only knows the next step. A packet travels hop by hop, and at every router the same question is asked: "Given this destination address, which neighbor should get it next?" It's like asking for directions in a series of towns, where each person only knows which road leads toward your destination.

It starts on your own computer, which makes a simple decision for every packet:

  • If the destination is on my subnet (same network part, according to my mask), deliver it directly: use ARP to find the destination's MAC address and send the frame.
  • If it's somewhere else, send it to my default gateway, the router on my subnet. The frame is addressed to the router's MAC address, while the IP packet inside still carries the final destination's IP address.

The gateway repeats the process with its own table. Across the internet, packets often pass through 10 to 20 routers. Internet providers exchange routing information with each other using BGP (Border Gateway Protocol), which is how the tens of thousands of networks that make up the internet learn how to reach each other. Inside organizations, protocols like OSPF keep routers' tables up to date automatically, and small networks often use simple static routes typed in by an administrator.

Step 2 of 13Diagram

Hop by hop from your laptop to a server

Hop by hop from your laptop to a serverProcess diagram: Laptop → Home router → Provider routers → Backbone networks → Destination network.LaptopHome routerProvider routersBackbone networksDestination network

Tap a shape with to see more.

Laptop

Destination is not local, so it sends the packet to its default gateway.

Home router

Its own default route points to the provider.

Provider routers

Look up the destination network and pick the next hop.

Backbone networks

Large providers exchange traffic using BGP routes.

Destination network

Its router delivers the packet onto the server's local network.

Step 3 of 13Learn

Reading a routing table

A routing table lists destination networks and where to send packets for each. A simplified table on an office router:

DestinationNext hopInterface
10.1.1.0/24directly connectedLAN1
10.1.2.0/24directly connectedLAN2
10.8.0.0/1610.1.2.254LAN2
0.0.0.0/0203.0.113.1WAN

The last line, 0.0.0.0/0, is the default route. With a /0 prefix it matches every address, so it catches anything not matched by a more specific line, usually sending it toward the internet.

When several routes match, the router chooses the longest prefix match, the most specific route. A packet for 10.8.4.20 matches both 10.8.0.0/16 and 0.0.0.0/0; the /16 is more specific, so it goes to 10.1.2.254. A packet for 198.51.100.7 matches only the default route and goes out the WAN.

You can see your own computer's table with ip route on Linux, route print on Windows or netstat -rn on macOS. On a typical laptop it has just two important lines: the local subnet and the default route via the home router.

When a route is missing or wrong, packets either go to the wrong place or are dropped with a "destination unreachable" message.

Step 4 of 13Practice · Choose one

Using the routing table above, where does the router send a packet addressed to 10.1.2.77?

Step 5 of 13Practice · Sort into groups

For a router with routes to 172.16.0.0/16, 172.16.5.0/24 and 0.0.0.0/0, sort each destination by the route that will be used.

Tap an item, then tap its group (or drag it there).

Step 6 of 13Practice · Diagram

Longest prefix match for 172.16.5.9

Which route does the router use for 172.16.5.9?

Tap the shape that answers the question, then press Check.

Longest prefix match for 172.16.5.9Scale: 0.0.0.0/0, 172.16.0.0/16, 172.16.5.0/24.0510152025300 prefix bits0.0.0.0/016 prefix bits172.16.0.0/1624 prefix bits172.16.5.0/24
0.0.0.0/0

Matches everything, so it is the last resort.

172.16.0.0/16

Matches: the first 16 bits agree.

172.16.5.0/24

Matches too, with 24 bits agreeing.

Step 7 of 13Learn

TTL and traceroute

What stops a packet from circling forever if two routers point at each other by mistake? Every IP packet carries a TTL (time to live) field, called hop limit in IPv6. The sender sets it, commonly to 64 or 128. Each router that forwards the packet subtracts 1. If the TTL reaches 0, the router discards the packet and sends an ICMP "time exceeded" message back to the sender. A routing loop therefore wastes some packets but never melts the network.

traceroute (tracert on Windows) turns this safety feature into a diagnostic tool. It sends packets with TTL 1, then 2, then 3, and so on. The router at each hop discards the packet whose TTL runs out there and replies, revealing its address and the round-trip time:

 1  192.168.1.1     1.2 ms
 2  10.20.0.1       8.9 ms
 3  203.0.113.45   11.4 ms
 4  * * *
 5  198.51.100.9   24.7 ms

Each line is a hop. Rising times show distance; a sudden large jump often marks a long-distance link or a congested router. Lines of * * * mean that router didn't reply, which is common and often harmless because many routers deprioritize or block these messages. If the trace stops completely at some hop and never continues, the path is likely broken there or traffic is filtered.

Step 8 of 13Practice · Work it out

A packet leaves a computer with a TTL of 64 and passes through 12 routers before reaching its destination. What TTL does the destination see?

Step 9 of 13Practice · True or false

A line of * * * in the middle of a traceroute always means the internet connection is broken at that point.

Step 10 of 13Practice · Chart

A traceroute from New York to a server in Europe

At which hop does the packet most likely cross the Atlantic?

Tap the point that answers the question, then press Check.

A traceroute from New York to a server in EuropeLine chart with 10 categories: Hop 1: 1 ms; Hop 2: 8 ms; Hop 3: 10 ms; Hop 4: 12 ms; Hop 5: 13 ms; Hop 6: 15 ms; Hop 7: 82 ms; Hop 8: 84 ms; Hop 9: 86 ms; Hop 10: 87 ms.0 ms20 ms40 ms60 ms80 ms100 msHop 1Hop 2Hop 3Hop 4Hop 5Hop 6Hop 7Hop 8Hop 9Hop 10
Illustrative trace.
A traceroute from New York to a server in Europe
ItemRound-trip time
Hop 11 ms
Hop 28 ms
Hop 310 ms
Hop 412 ms
Hop 513 ms
Hop 615 ms
Hop 782 ms
Hop 884 ms
Hop 986 ms
Hop 1087 ms

Step 11 of 13Note

Step 12 of 13Practice · Match the pairs

Match each routing term to its meaning.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. Default route
  2. Next hop
  3. Longest prefix match
  4. BGP

Step 13 of 13Practice · What would you do?

What would you do?

Users at a branch office can reach every server in their own subnet (10.5.1.0/24) but nothing at headquarters or on the internet. Their PCs have the correct IP addresses and mask. What should you check first?