DEV Community

Cover image for TCP: Why the Internet Works Even When It's Broken
Doogal Simpson
Doogal Simpson

Posted on • Originally published at doogal.dev

TCP: Why the Internet Works Even When It's Broken

TL;DR: TCP is how we send big files over a mess of unreliable cables. It chops data into numbered chunks and won't stop nagging the receiver until every single piece is accounted for. If a packet gets dropped or a router chokes, TCP just resends it until the job is done.

The internet is a series of physical cables and aging hardware that is constantly failing. Between your computer and a server, there are dozens of points of failure where data can be lost, corrupted, or just dropped because a router got too hot. TCP (Transmission Control Protocol) is the protocol that keeps your data from becoming a corrupted mess by assuming the network is going to fail.

How does TCP handle data loss on an unreliable network?

TCP handles data loss by breaking large files into small chunks and requiring a formal acknowledgment for every single one. Instead of hoping a 1GB file arrives in one piece, it treats the network as a "best-effort" medium and takes full responsibility for verifying that every byte landed safely.

Sending a massive file over a physical wire is a gamble. If one bit flips or a single packet hits a congested router and gets dropped, the whole transmission is ruined. TCP doesn't gamble. It puts every page of your data into its own envelope, labels it with a page number, and sends it out. Then, it waits for a phone call. If the recipient says they got pages 1, 2, and 4, the sender knows page 3 was lost in the mail. The sender doesn't have to guess; they just grab a copy of page 3 and send it again until the recipient confirms they have it.

What is the step-by-step process of TCP data transmission?

TCP transmission follows a strict loop of segmentation, sequencing, and verification. It transforms a raw, unreliable stream of bits into a structured conversation between two machines to ensure the final payload is identical to the source.

Phase What Happens Why it Matters
Segmentation Chop the payload into MTU-sized segments. Keeps chunks small enough for hardware to handle without choking.
Sequencing Stamp every packet with a sequence ID. Lets the receiver rebuild the file in order, even if packets arrive late.
Transmission Push segments onto the physical wire. This is the "unreliable" part where cables and routers take over.
ACK Loop Wait for Acknowledgment (ACK) signals. The only way the sender knows the data actually arrived.
Retransmit Resend segments if an ACK times out. Fixes network errors automatically without the user ever noticing.

Why does TCP use sequence numbers for every packet?

Sequence numbers act as the index that allows the receiver to reassemble data in the correct order and identify gaps. Without these numbers, the receiver would have no way of knowing if a packet was missing or if the data arrived out of sequence.

Think about a high-res image being sent across the country. Packet #50 might take a faster route through the network and arrive before packet #49. Without sequence numbers, your computer would just stick the bits together in the order they arrived, and the image would look like static. The sequence number tells the OS exactly where that chunk belongs in the final file, allowing it to buffer early arrivals until the missing gaps are filled.

What happens when a TCP acknowledgment is never received?

When an acknowledgment (ACK) doesn't return within a specific window, the sender assumes the packet died in transit and triggers a retransmission. It keeps the data in a local buffer and refuses to clear it until it's 100% sure the other side has it.

This is the core of TCP's reliability. If you are pushing code to a server and the connection flutters, TCP doesn't just let that chunk of data vanish. It will keep retrying that specific sequence ID until the server finally responds with a green light. It’s a persistent, nagging mechanism that ensures the integrity of the data at the cost of some overhead.

FAQ

What is the cost of TCP reliability?
The primary cost is high-latency overhead. Because every packet requires an acknowledgment (the ACK), and there is a "handshake" to start the connection, TCP is naturally slower than protocols that just fire data into the void without checking if it landed.

Why use TCP over UDP?
You use TCP when accuracy is non-negotiable, like loading a website, sending an email, or downloading software. You use UDP when speed is more important than a few dropped packets, like in a Zoom call or a competitive multiplayer game where a momentary glitch is better than the whole stream pausing to wait for a retransmission.

Does TCP ever give up on resending data?
Yes. While TCP is persistent, it isn't infinite. If it fails to get an ACK after a set number of retries or a specific timeout period, it will eventually "reset" the connection and signal to the application that the network path is dead.

Top comments (0)