# Packets & Routing

> Data travels the web as tiny chunks across independent paths, not as a single stream.

Subject: Internet | Lesson 2 of 35 | 3 min read
Interactive lesson: https://codewithanimation.in/internet/packets-and-routing
Previous: [The Internet](https://codewithanimation.in/internet/the-internet.md) | Next: [TCP/IP Suite](https://codewithanimation.in/internet/tcp-ip-suite.md)

## What are Packets?

Data on the web doesn't travel as a single continuous stream. Instead, it is chopped up into tiny chunks called **packets**. Each packet is individually wrapped with destination information and navigates the vast network of routers independently, finding its own path to the destination where everything is stitched back together.

## Why chunk data into packets?

Think of the internet like the global postal service. If you wanted to mail a massive book, you wouldn't send the entire book in one giant envelope. If it got lost, you'd lose everything.

Instead, tearing it into individual pages and mailing each one separately allows multiple computers to share the same physical lines (like cars sharing a highway). If a single packet gets lost in transit, you only need to retransmit that tiny piece, making the network far more efficient and resilient.

## How Routing Works (TCP vs UDP)

The physical machines that pass these packets along are called **Routers**. Every packet has a header containing the destination IP address. When a router receives a packet, it reads the address and forwards it to the next closest router. Because the network is chaotic, packets from the same image might take completely different geographical routes and arrive out of order!

The protocol that manages this chunking and reassembly is called **TCP** (Transmission Control Protocol). TCP guarantees that every single packet arrives and is put back in the exact right order. If a packet gets lost, TCP notices the missing sequence number and asks the sender to resubmit just that one packet. This reliability makes TCP perfect for loading websites.

**UDP** (User Datagram Protocol) is the alternative. It sends packets as fast as possible but doesn't check if they arrive. If a packet is lost, it's gone forever. UDP is used for live video streams and multiplayer games where speed matters more than perfect accuracy.

## Common mistake: The Phone Call Fallacy

A common mistake is thinking data travels as a continuous stream over a single, dedicated, unbroken physical connection (like an old telephone line). In reality, the connection is virtual, and packets are constantly being routed and rerouted dynamically.

## Tip: Network Payload Analysis

Use the Chrome DevTools Network tab to inspect your site's payloads. The Waterfall view physically visualizes the time it takes for these packets to make their round-trips and get reassembled!

## Try it: The TCP Packet Swarm

Tap 'Send Payload' to watch a file break down into packets. Try tapping a packet to drop it and see how TCP tracks the missing data!

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/internet/packets-and-routing

## Check yourself

### Question 1

Why is data chopped into small packets instead of being sent as one huge file?

- A. To bypass network firewalls and security filters.
- B. Because web browsers can only read data in 1KB chunks.
- C. To make the internet run faster by sending data over a single, dedicated wire.
- D. So multiple users can share the network, and if a piece is lost, only that small chunk needs to be resent.

Correct answer: D

Packet switching allows multiple computers to share the same physical lines. If a packet is lost in transit, you only need to retransmit that tiny piece.

- Why not A: Firewalls inspect packets; they don't block based simply on whether data is packetized.
- Why not B: Browsers can process large streams; packetizing is a network-level requirement, not a browser limitation.
- Why not C: Packet switching actually avoids dedicated wires, allowing networks to be shared.

### Question 2

What is the primary difference between TCP and UDP?

- A. TCP guarantees reliable, ordered delivery of packets, whereas UDP sends packets quickly without checking if they arrived.
- B. TCP is used for mobile devices, while UDP is for desktop computers.
- C. TCP is faster but less reliable, while UDP guarantees delivery.
- D. TCP encrypts data automatically, while UDP leaves it as plain text.

Correct answer: A

TCP ensures every packet reaches its destination and is assembled in the correct order. UDP favors pure speed, making it ideal for live video or fast paced gaming.

- Why not B: Both protocols are used across all device types and networks.
- Why not C: It is the exact opposite. TCP is the reliable one.
- Why not D: Neither protocol provides built-in encryption; that is handled by TLS/SSL higher up the stack.

### Question 3

If a single packet from a large image file gets lost during transmission, what happens?

- A. The browser displays the image with a visible missing square.
- B. The entire image file must be re-downloaded from the server.
- C. The receiver's TCP layer notices a packet is missing and asks the sender to retransmit only that specific packet.
- D. The router that lost the packet automatically generates a replacement.

Correct answer: C

TCP uses sequence numbers to track packets. If a gap is detected at the destination, the receiver requests a retransmission, ensuring the file is perfectly reassembled.

- Why not A: Over TCP, the browser waits for the complete, correct data before it considers the image fully downloaded.
- Why not B: TCP is smart enough to only request the specific missing packet, saving bandwidth.
- Why not D: Routers don't keep backups of the original data; the sender has to recreate or resend it.

## Remember this

- Data is broken into tiny packets to efficiently share network lines and recover from errors.
- TCP is slow but perfectly reliable (used for the Web). UDP is fast but drops data (used for gaming/video).
- Packets travel independently across decentralized routers and may arrive out of order.
