Packets and Routing
Discover why the internet splits data into packets, what a packet header contains, how routers choose paths and what traceroute reveals.
Welcome back!
Step 1 of 13Learn
Mailing a book one page at a time
Imagine you need to mail a 300-page book to a friend, but the post office only accepts postcards. You'd number each page, write your friend's address and your own on every card, and drop them all in the mailbox. The cards might travel on different trucks and arrive out of order, but your friend can sort them by number and rebuild the book. If a card goes missing, your friend can ask you to resend page 147.
That's essentially how the internet moves data. Every photo, message and video is chopped into small chunks called packets, often around 1,500 bytes or less each. A single high-definition photo can become a few thousand packets.
This approach is called packet switching, and it's one of the most important ideas in networking. The older telephone network used circuit switching: a call reserved a dedicated path for its whole duration, even during silences. Packet switching instead lets millions of conversations share the same cables, with packets from everyone interleaved like cars merging on a highway.
The benefits are huge: links are used efficiently, no single conversation hogs a line, and if part of the network fails, packets can simply take another route. That resilience was one of the original goals of the research that produced the internet.
Step 2 of 13Practice · Choose one
What is the main advantage of packet switching over circuit switching?
Step 3 of 13Compare
Circuit switching vs packet switching
| Aspect | Circuit switching (old phone network) | Packet switching (internet) |
|---|---|---|
| Path | One reserved path for the whole call | Each packet routed separately |
| Idle time | Line is held even in silence | Links are shared by everyone |
| If a link fails | Call drops | Packets go around the problem |
| Efficiency | Wastes capacity | Uses capacity fully |
Step 4 of 13Learn
Inside a packet
Each packet has two main parts:
- The header, like the writing on an envelope: the source IP address, the destination IP address, information about which protocol is inside, and a counter that limits how long the packet can wander.
- The payload: the actual chunk of data, such as part of a webpage, a slice of a video or a few words of a chat message.
That counter is called TTL (time to live) in IPv4 and hop limit in IPv6. (It's a different TTL from the DNS caching timer, despite the shared name.) It starts at a number like 64, and each router that handles the packet subtracts one. If it reaches zero, the router throws the packet away. This prevents packets from looping forever if routes get misconfigured.
Packets are also wrapped in layers. Your data is placed inside a transport-layer segment (such as TCP), which is placed inside an IP packet, which is placed inside a frame for the local link, such as Wi-Fi or Ethernet. At each hop, routers unwrap the outer frame, read the IP header, and rewrap the packet for the next link. This nesting, called encapsulation, is like putting a letter in an envelope, then in a mailbag, then in a truck.
Step 5 of 13Practice · Sort into groups
Is each item found in a packet's header or its payload?
Tap an item, then tap its group (or drag it there).
Step 6 of 13Diagram
Anatomy of an IP packet
Tap a shape with to see more.
- IP packet
- Source address
Where it came from, so replies can find their way back.
- Destination address
What every router reads to decide where to send it next.
- Protocol
What is inside: TCP, UDP or something else.
- TTL (hop limit)
Drops by 1 at each router; the packet is discarded at 0.
- Payload
The actual data: a piece of a web page, a video frame, a message.
Step 7 of 13Learn
How routers pick a path
A router is a device that forwards packets between networks. Your home router connects your house to your ISP; huge routers at ISPs and internet exchange points handle enormous traffic.
Each router keeps a routing table, a list that says, roughly, "for addresses in this range, send packets out through that connection." When a packet arrives, the router reads the destination address, finds the best matching entry and sends the packet toward the next router, called the next hop. No router knows the whole path; each one only knows the next step. It's like asking for directions in a series of towns, where each person points you toward the next town.
Between large networks, routes are exchanged using BGP (Border Gateway Protocol). Each major network announces which addresses it can reach, and neighbors share this information, building a picture of how to get anywhere. BGP is powerful but trust-based. When a network accidentally announces routes it shouldn't, traffic can be misdirected, which has caused several large outages over the years.
A tool called traceroute (tracert on Windows) shows the routers a packet passes through. It works by sending packets with TTL 1, then 2, then 3 and so on. Each router that drops a packet with TTL zero sends back an error message, revealing itself. A typical path to a distant website might pass through 10 to 20 routers.
Step 8 of 13Practice · True or false
Each router on a packet's route knows the complete path from source to destination.
Step 9 of 13Practice · Work it out
A packet leaves your computer with a TTL of 64. After passing through 12 routers, what is its TTL?
Step 10 of 13Note
Step 11 of 13Practice · Chart
A sample traceroute
Tap the first hop on the far side of the ocean.
Tap the point that answers the question, then press Check.
| Item | Round-trip time |
|---|---|
| Hop 1 | 2 ms |
| Hop 2 | 9 ms |
| Hop 3 | 11 ms |
| Hop 4 | 13 ms |
| Hop 5 | 15 ms |
| Hop 6 | 84 ms |
| Hop 7 | 87 ms |
| Hop 8 | 89 ms |
Step 12 of 13Practice · Put in order
Put these events in the order they happen when a packet travels to a website.
Drag the items, or use the arrow buttons, to put them in order.
- Your home router forwards it to your ISP
- ISP and backbone routers each pick the next hop
- The packet arrives at the website's network
- The server reassembles the packets into the original data
- Your device puts the destination IP address in the packet header
Step 13 of 13Practice · Choose one
What is the purpose of the TTL (hop limit) field in an IP packet?
Lesson complete!