One big message does not fit in one piece

When you send a photo, a chat message or a web page, it does not travel as one block. The internet cuts it into many small pieces called packets. Each packet is a short chunk of your data with a label on the front saying where it is going and which piece it is.

Why cut things up? Because the network is shared. If one huge message occupied a cable for a whole minute, everyone else would have to wait. Small packets let thousands of conversations take turns on the same wires. A single packet is also small enough that, if it gets damaged or dropped, you only need to send that one piece again, not the whole message.

On many networks a packet can hold at most about 1,500 bytes (that limit is called the MTU, short for maximum transmission unit). Some of those bytes are used by the labels, so a typical packet carries a bit under 1,500 bytes of your actual data. A photo of a few megabytes therefore becomes thousands of packets.

What is on the label?

Every packet has a header (the label) and a payload (your data). The header of the Internet Protocol, IP, holds the sender's address and the destination address. If you read the article about IP addresses and ports, this is where those numbers live. The header of TCP, the protocol that sits on top of IP for most web traffic, adds a sequence number: it says where this piece belongs in the whole message.

The sequence number matters because packets do not promise to arrive in order. Routers (the machines that forward packets) can send neighbouring packets down different paths, and one path may be quicker than another. Piece 5 may overtake piece 3.

Try it: send a message through a messy network

Type a message, choose how many characters fit in one packet, and press Send. The packets leave in order but arrive shuffled. The receiver puts each piece into its numbered slot, so the message still comes out right. Turn on Drop one packet to see what happens when the network loses a piece.

Message to send
On the wire (arrival order)
Receiver's numbered slots
Message the receiver can read
Each box shows the text and its sequence number. Orange means missing.

Lost pieces and "are you there?"

Networks do drop packets. A router can be overloaded, or a wireless signal can fade for a moment. TCP deals with this using acknowledgements: the receiver tells the sender which pieces it has received. If the sender does not hear back about a piece within a short time, it sends that piece again. That is what the "Ask for missing piece" button stands for. In real life it happens automatically, in milliseconds, and you only notice it as a slight slowdown.

This is why TCP is called reliable: the message that comes out is the message that went in, even though the network underneath is not reliable. Other protocols, such as UDP, skip this bookkeeping. They are faster to start and are used where a late packet is useless anyway, such as in many live calls and games. A dropped moment of video is better skipped than replayed late.

The same idea in a few lines of Python

Here is the core trick, with a list in place of a network. We cut a string into numbered pieces, shuffle them as a messy network might, then sort by number to rebuild the message.

import random

message = "Hello from the other side of the internet!"
SIZE = 8

packets = []
for i in range(0, len(message), SIZE):
    packets.append({"seq": i // SIZE, "data": message[i:i + SIZE]})

random.seed(4)
random.shuffle(packets)          # the network may deliver them in any order
print("arrived:", [(p["seq"], p["data"]) for p in packets])

packets.sort(key=lambda p: p["seq"])
print("rebuilt:", "".join(p["data"] for p in packets))

Running it with Python 3 prints this (the shuffle is fixed by random.seed(4); the exact order can differ on other Python versions, but the rebuilt line is always the same):

arrived: [(3, 'e of the'), (5, 't!'), (4, ' interne'), (0, 'Hello fr'), (2, 'ther sid'), (1, 'om the o')]
rebuilt: Hello from the other side of the internet!

What this means for you

You will rarely handle packets yourself, because your browser and your programming language's networking libraries do it for you. But knowing they exist explains several everyday things. A page that loads in stages is receiving many pieces. A video call that freezes is waiting for pieces that are late or lost. Sending many small requests costs more than one bigger request, because each one pays the price of its own headers and its own trip. And when someone says "my connection is slow", the cause might be low bandwidth (few pieces per second) or high latency (each piece takes a long time to arrive). Those are different problems.

The big idea to keep: the internet is built from unreliable parts, and reliability comes from adding numbers and acknowledgements on top. Many things in computing work this way.