edubun
English
1 / 22

3 / 6 · Basic

How packets find their way

Each router lowers a packet's TTL by one. When it reaches 0 the packet is thrown away, so a packet caught in a loop cannot circle forever.

Jump to the 10 practice questions

You will learn

  • Follow the TTL countdown and what traceroute does with it
  • Pick the next hop by the longest matching prefix
  • Explain where lost packets come from

Before this: IP addresses

1Explore

Try the simulator first

Try the simulator before reading anything else. Set TTL to 2 and press Send, then set it to 64 and send again. Watch where the packets stop the first time.

Loading

Drag to turn. Scroll or pinch to zoom.

Set TTL to 2 and press Send: every packet dies at the second router it meets, R1 or R2, and a red ICMP message comes back. Set it to 64 and the packets get through with TTL 60, after four routers. The traceroute button sends probes with TTL 1 to 5 and lists who answered. Cut R1 to R3 and send again to watch the packets go around.

2Explain

What you just saw: a countdown in every packet

With TTL 2, every packet died at the second router it met and a red message came back. With 64, the packets reached the server with 60 left after four routers. The IPv4 header has an 8-bit field called Time to Live (TTL), so its largest value is 255. RFC 791 says every router must lower it by at least one, and many computers start it at 64. When it reaches 0 the router drops the packet and sends an ICMP "Time Exceeded" message (RFC 792) back to the sender.

3Problem

TTL after four routers

A packet leaves with TTL 64 and passes 4 routers. What is its TTL when it arrives?

Hint

Each router takes off one.

Solution

Answer: 60

Each router lowers TTL by 1: 64 − 4 = 60.

4Problem

The largest TTL

TTL is an 8-bit field. What is the largest value it can hold?

Hint

An 8-bit field.

Solution

Answer: 255

Because 0 is one of the patterns, the largest value is one below the count: 2⁸ − 1 = 255. The number of patterns and the largest label are different.

5Problem

TTL reaches 0

What does a router do when a packet's TTL reaches 0?

Hint

The red message in the simulator.

Solution

Answer: Drops it and sends ICMP Time Exceeded to the sender

RFC 791 and RFC 792: the packet is discarded and an ICMP message reports it.

6Explain

Why a countdown

Why have a countdown at all? A mistake in the routing tables could send a packet round in a circle, and without a limit it would use links forever. The name says "time", and on paper RFC 791 measures it in seconds. But every router takes off at least one, so in practice it works as a count of hops. IPv6 gave the same field a plainer name, Hop Limit.

7Problem

Why TTL exists

Why does TTL exist?

Hint

A loop in the tables.

Solution

Answer: So a packet caught in a routing loop cannot circle forever

Without a countdown a looping packet would use links forever.

8Explain

How traceroute draws a map

The traceroute button uses this rule to draw a map. It sends a probe with TTL 1: the first router drops it and replies, which reveals that router's address. TTL 2 reveals the second router, and so on until the destination answers. Press it and read the list it builds. Then cut R1 to R3 and send again to see the packets take another way.

9Problem

A probe with TTL 1

traceroute sends a probe with TTL 1. Who answers?

Hint

The first router lowers it to 0.

Solution

Answer: The first router on the path

The first router lowers TTL to 0, drops the probe and replies with ICMP Time Exceeded.

10Explain

Each router looks up one line in a table

No router knows the whole route from your laptop to a server on another continent. Each one makes a single decision: for this destination address, which neighbour gets the packet next? The packet moves one hop, and the next router decides again. A route is a chain of these local choices.

11Explain

The longest prefix wins

The decision comes from a forwarding table, a list of prefixes, each with the neighbour to use. The router picks the entry that matches the destination with the longest prefix, because a longer prefix is a more exact match. Say the table sends 203.0.0.0/16 to neighbour B and 203.0.113.0/24 to neighbour A. A packet for 203.0.113.9 matches both, the /24 wins, and it goes to A. A packet for 203.0.7.1 matches only the /16, so it goes to B. Most tables also have a default entry for everything else; in a home router it points to the ISP.

Packet forEntries that matchSent to
203.0.113.9203.0.113.0/24 (A), 203.0.0.0/16 (B), default (ISP)A, longest (24 bits)
203.0.7.1203.0.0.0/16 (B), default (ISP)B, longest (16 bits)
8.8.8.8default 0.0.0.0/0 (ISP)ISP

12Problem

203.0.113.9

A table has 203.0.113.0/24 → A and 203.0.0.0/16 → B. Where does a packet for 203.0.113.9 go?

Hint

Both entries match; which prefix is longer?

Solution

Answer: A

Both match; the longest prefix (/24) wins.

13Problem

203.0.7.1

Same table. Where does a packet for 203.0.7.1 go?

Hint

Only the /16 matches.

Solution

Answer: B

203.0.7.1 does not start with 203.0.113, so only the /16 matches.

14Explain

Who writes the tables

Inside one company, routers share what they can reach using routing protocols and work out new paths when a link fails. Between the tens of thousands of separate networks that make up the internet, the Border Gateway Protocol (BGP, RFC 4271) carries announcements such as "I can reach 198.51.100.0/24". When a cable is cut, routes through it are withdrawn and traffic shifts to whatever path is left. In the simulator, that is what happened when you cut R1 to R3.

15Problem

Between networks

Which protocol carries route announcements between the separate networks of the internet?

Hint

Border Gateway Protocol.

Solution

Answer: BGP

The clue is announcements between separate networks: BGP-4, defined in RFC 4271, tells other networks which prefixes are reachable. This is routing information, not a web page transfer.

16Problem

Cut R5 to the server

In the simulator you cut R5 to the server. What happens?

Hint

How many links does the server have?

Solution

Answer: Nothing gets through: the server has only one link

Rerouting needs a second path. A single link is a single point of failure.

17Explain

Most lost packets fall out of a full queue

Routers also make packets wait. At busy moments packets arrive faster than an outgoing link can carry them, so each router keeps a queue in memory. When the queue is full, the next packet to arrive is simply dropped. Nobody is told; the sender can only work it out later. This is the most common way packets go missing on the internet, more common than a cut cable. A weak Wi-Fi signal can also spoil a frame so that it has to be thrown away. IP itself promises nothing.

18Explore

A 3,000,000-byte photo is 2055 packets

Links limit how big one packet may be. On Ethernet one frame carries at most 1500 bytes of payload (RFC 894). Take away 20 bytes of IPv4 header and 20 bytes of TCP header, and about 1460 bytes of your data fit in each packet. A 3,000,000-byte photo therefore needs 3,000,000 ÷ 1460 ≈ 2054.8, rounded up to 2055 packets, and each one is routed on its own.

Math.ceil rounds up: a part-filled last packet still counts as a packet.

Bytes
const bytes = 3000000;
console.log(Math.ceil(bytes / 1460));
Output
2055

19Problem

Packets for 3,000,000 bytes

About 1460 bytes of data fit in one packet. How many packets does a 3,000,000-byte file need?

packets

Hint

3,000,000 ÷ 1460, rounded up.

Solution

Answer: 2055 packets

3,000,000 ÷ 1460 ≈ 2054.8, so round up to 2055. A partially filled final packet still counts; rounding down would leave some file data unsent.

20Practice

Longest prefix match

The table, num and matches are given. Finish nextHop(ip): among the entries that match the address, return the "to" of the one with the longest prefix.

Expected output
A
B
ISP
Your code
const table = [
  { prefix: "203.0.113.0", len: 24, to: "A" },
  { prefix: "203.0.0.0", len: 16, to: "B" },
  { prefix: "0.0.0.0", len: 0, to: "ISP" },
];
const num = (ip) => ip.split(".").reduce((n, x) => n * 256 + Number(x), 0);
const matches = (ip, e) => Math.floor(num(ip) / 2 ** (32 - e.len)) === Math.floor(num(e.prefix) / 2 ** (32 - e.len));
function nextHop(ip) {
  for (const e of table) {
    // keep the matching entry with the largest len
  }
  return "ISP";
}
console.log(nextHop("203.0.113.9"));
console.log(nextHop("203.0.7.1"));
console.log(nextHop("8.8.8.8"));
Hint

Keep the best entry so far and replace it only by a longer match.

A solution
const table = [
  { prefix: "203.0.113.0", len: 24, to: "A" },
  { prefix: "203.0.0.0", len: 16, to: "B" },
  { prefix: "0.0.0.0", len: 0, to: "ISP" },
];
const num = (ip) => ip.split(".").reduce((n, x) => n * 256 + Number(x), 0);
const matches = (ip, e) => Math.floor(num(ip) / 2 ** (32 - e.len)) === Math.floor(num(e.prefix) / 2 ** (32 - e.len));
function nextHop(ip) {
  let best = null;
  for (const e of table) {
    if (matches(ip, e) && (best === null || e.len > best.len)) best = e;
  }
  return best.to;
}
console.log(nextHop("203.0.113.9"));
console.log(nextHop("203.0.7.1"));
console.log(nextHop("8.8.8.8"));

21Explain

Common mistakes

  • "Each router knows the whole path to the server."

    Each router only picks the next hop from its forwarding table. The route is whatever chain those single choices make, and packets of the same message can take different routes.

  • "TTL is how many seconds a packet has left."

    RFC 791 does describe it in seconds, but every router must take off at least one, so in practice it counts hops. IPv6 renamed it Hop Limit. The TTL on a DNS record is a different value with the same name, and that one really is in seconds.

  • "Most lost packets come from broken cables."

    Most are dropped by busy routers whose queues are full, and a weak Wi-Fi signal spoils frames too. A cut cable is rarer, and the routers can often send traffic around it.

  • "IP makes sure every packet arrives."

    RFC 791 says IP does not provide a reliable communication facility: no acknowledgements, no retransmissions. Recovery is done by the two end computers, usually with TCP.

22

Summary

  • Routers decide one hop at a time using a forwarding table; the longest matching prefix wins.
  • BGP spreads route announcements between networks and withdraws routes when links fail.
  • TTL (IPv6: Hop Limit) drops by 1 per router; at 0 the packet is dropped and ICMP reports it.
  • traceroute maps a path by sending TTL 1, 2, 3 and so on.

Next unitTCP, UDP and ports
Full text · The whole lesson as one text

Try the simulator before reading anything else. Set TTL to 2 and press Send, then set it to 64 and send again. Watch where the packets stop the first time.

Set TTL to 2 and press Send: every packet dies at the second router it meets, R1 or R2, and a red ICMP message comes back. Set it to 64 and the packets get through with TTL 60, after four routers. The traceroute button sends probes with TTL 1 to 5 and lists who answered. Cut R1 to R3 and send again to watch the packets go around.

What you just saw: a countdown in every packet

With TTL 2, every packet died at the second router it met and a red message came back. With 64, the packets reached the server with 60 left after four routers. The IPv4 header has an 8-bit field called Time to Live (TTL), so its largest value is 255. RFC 791 says every router must lower it by at least one, and many computers start it at 64. When it reaches 0 the router drops the packet and sends an ICMP "Time Exceeded" message (RFC 792) back to the sender. That was the red message.

Why have a countdown at all? A mistake in the routing tables could send a packet round in a circle, and without a limit it would use links forever. The name says "time", and on paper RFC 791 measures it in seconds. But every router takes off at least one, so in practice it works as a count of hops. IPv6 gave the same field a plainer name, Hop Limit.

The traceroute button uses this rule to draw a map. It sends a probe with TTL 1: the first router drops it and replies, which reveals that router's address. TTL 2 reveals the second router, and so on until the destination answers. Press it and read the list it builds. Then cut R1 to R3 and send again to see the packets take another way.

Each router looks up one line in a table

No router knows the whole route from your laptop to a server on another continent. Each one makes a single decision: for this destination address, which neighbour gets the packet next? The packet moves one hop, and the next router decides again. A route is a chain of these local choices.

The decision comes from a forwarding table, a list of prefixes, each with the neighbour to use. The router picks the entry that matches the destination with the longest prefix, because a longer prefix is a more exact match. Say the table sends 203.0.0.0/16 to neighbour B and 203.0.113.0/24 to neighbour A. A packet for 203.0.113.9 matches both, the /24 wins, and it goes to A. A packet for 203.0.7.1 matches only the /16, so it goes to B. Most tables also have a default entry for everything else; in a home router it points to the ISP.

Packet forEntries that matchSent to
203.0.113.9203.0.113.0/24 (A), 203.0.0.0/16 (B), default (ISP)A, longest (24 bits)
203.0.7.1203.0.0.0/16 (B), default (ISP)B, longest (16 bits)
8.8.8.8default 0.0.0.0/0 (ISP)ISP

Who writes the tables

Inside one company, routers share what they can reach using routing protocols and work out new paths when a link fails. Between the tens of thousands of separate networks that make up the internet, the Border Gateway Protocol (BGP, RFC 4271) carries announcements such as "I can reach 198.51.100.0/24". When a cable is cut, routes through it are withdrawn and traffic shifts to whatever path is left. In the simulator, that is what happened when you cut R1 to R3.

Most lost packets fall out of a full queue

Routers also make packets wait. At busy moments packets arrive faster than an outgoing link can carry them, so each router keeps a queue in memory. When the queue is full, the next packet to arrive is simply dropped. Nobody is told; the sender can only work it out later. This is the most common way packets go missing on the internet, more common than a cut cable. A weak Wi-Fi signal can also spoil a frame so that it has to be thrown away. IP itself promises nothing. RFC 791 says it does not provide a reliable communication facility, with no acknowledgements and no retransmissions. Getting lost data back is left to the computers at the two ends, and that is the next unit.

A 3,000,000-byte photo is 2055 packets

Links limit how big one packet may be. On Ethernet one frame carries at most 1500 bytes of payload (RFC 894). Take away 20 bytes of IPv4 header and 20 bytes of TCP header, and about 1460 bytes of your data fit in each packet. A 3,000,000-byte photo therefore needs 3,000,000 ÷ 1460 ≈ 2054.8, rounded up to 2055 packets, and each one is routed on its own.

Common mistakes
  • "Each router knows the whole path to the server." Each router only picks the next hop from its forwarding table. The route is whatever chain those single choices make, and packets of the same message can take different routes.
  • "TTL is how many seconds a packet has left." RFC 791 does describe it in seconds, but every router must take off at least one, so in practice it counts hops. IPv6 renamed it Hop Limit. The TTL on a DNS record is a different value with the same name, and that one really is in seconds.
  • "Most lost packets come from broken cables." Most are dropped by busy routers whose queues are full, and a weak Wi-Fi signal spoils frames too. A cut cable is rarer, and the routers can often send traffic around it.
  • "IP makes sure every packet arrives." RFC 791 says IP does not provide a reliable communication facility: no acknowledgements, no retransmissions. Recovery is done by the two end computers, usually with TCP.
Teacher's noteLet learners break things before you explain anything: TTL 2, then 64, then a cut link. Once they have watched a packet die, most of their questions answer themselves. Longest-prefix matching is where they stall. Work the two-entry table by hand, writing the addresses one above the other so the shared start is visible, and only then add the default entry. Keep the two kinds of TTL apart from the start, because the DNS unit uses the same three letters for a number of seconds.
Key points
  • Routers decide one hop at a time using a forwarding table; the longest matching prefix wins.
  • BGP spreads route announcements between networks and withdraws routes when links fail.
  • TTL (IPv6: Hop Limit) drops by 1 per router; at 0 the packet is dropped and ICMP reports it.
  • traceroute maps a path by sending TTL 1, 2, 3 and so on.

Practice questions from How packets find their way on edubun

Embed this quiz

Free to embed. Please keep the credit line.

Sources for this course (27)
  • (checked 2026-10-17)
  • IETF RFCs (rfc-editor.org): RFC 768 UDP (1980, 8-byte header)
  • RFC 791 IPv4 (1981, 32-bit addresses, "does not provide a reliable communication facility", TTL field "measured in units of seconds" but every module must decrease it by at least one, so it is only an upper bound)
  • RFC 792 ICMP (Time Exceeded)
  • RFC 801 NCP/TCP transition plan (1 January 1983)
  • RFC 894 Ethernet (1500-byte payload)
  • RFC 1034 and RFC 1035 DNS (1987, HOSTS.TXT kept by SRI-NIC, labels up to 63 octets and names up to 255, TTL in seconds)
  • RFC 1122 (127.0.0.0/8 loopback)
  • RFC 1918 private addresses (10/8, 172.16/12, 192.168/16)
  • RFC 2131 DHCP, RFC 3022 NAT, RFC 3596 AAAA records, RFC 3849 and RFC 5737 documentation addresses, RFC 4271 BGP-4, RFC 4291 IPv6 text form, RFC 6298 TCP retransmission timer (initial RTO 1 second)
  • RFC 6335 port ranges (0-1023, 1024-49151, 49152-65535)
  • RFC 7766 DNS over TCP, RFC 8200 IPv6 (128-bit addresses, Hop Limit)
  • RFC 8446 TLS 1.3 (one round-trip handshake)
  • RFC 9000 QUIC and RFC 9114 HTTP/3, RFC 9110 HTTP semantics (status code classes)
  • RFC 9293 TCP (three-way handshake, sequence numbers)
  • IANA: ip-parameters registry (recommended default TTL 64)
  • IPv4 free pool depleted 3 February 2011 (NRO and ARIN announcements)
  • Official documentation: MDN Web Docs "How does the Internet work?" (45 cables for 10 computers, switches, routers, MAC and IP addresses, internet and web)
  • "What is a URL?", "HTTP response status codes" (developer.mozilla.org)
  • Cloudflare Learning Center: "What is DNS?" (four kinds of DNS server, 8 steps of an uncached lookup, browser and OS caches, TTL)
  • "What is HTTP/3?" (cloudflare.com/learning)
  • Google Chrome Help, "Browse in Incognito mode" (support.google.com/chrome/answer/95464, checked 2026-10-19: Incognito limits what is saved to the device; websites and organisations that manage your network, like your school, employer or internet service provider, may be able to observe your activity)
  • Operators and papers: root-servers.org (13 root name servers run by 12 organisations, 2047 instances on 2026-10-17)
  • Jacobson and Karels 1988, Congestion Avoidance and Control (loss mostly congestion)
  • History blocks only: UCLA Samueli School of Engineering, Internet50 (first ARPANET message "LO", UCLA to SRI, 29 October 1969, 22:30)
  • historyofinformation.com and Wikipedia ARPANET (Kline)
  • Spiceworks/SRI history (HOSTS.TXT kept by SRI-NIC).

Checked: 2026-10-17