How does TCP work
What if one page of a letter you sent went missing on the way, or the last page arrived first? Packets on the internet have the same problem: some get lost, and some arrive out of order. That messages still arrive intact is thanks to TCP.
Nothing Missing, Everything in Place
As we saw, data becomes small pieces called packets that cross over by separate routes. But those routes are not perfect. A piece can vanish on the way, or a later piece can arrive first.
Even so, the receiver must get every piece, in order. The agreement in charge of that is TCP.
Tap the two cards to switch on the two promises TCP keeps: nothing goes missing, and everything arrives in the order it was sent.
The goal is clear: nothing missing, everything in order. It is easy to say, but with imperfect routes it is hard to keep.
TCP manages it with three habits: saying it got something, sending again when nothing comes back, and putting things in order by number.
As an aside, before sending any data, TCP first sets up a connection by exchanging a short three-way greeting with the other side.
Saying "Got It"
The first habit is acknowledgment. Each time a piece arrives, the receiver replies briefly, "Got it," and this reply is called an acknowledgment, or ACK.
It is like pressing "received" after a parcel is delivered. Only when an ACK comes back does the sender know that piece arrived safely. Without an ACK, it simply does not know yet.
Tap each packet that has arrived and the receiver sends back an acknowledgment (ACK). Once all four have been acknowledged, the sender knows everything got through.
With an ACK going back for each piece, the sender learned which pieces had arrived. One extra message per piece may make things look a little slower.
But thanks to that one word, a missing piece can be pinpointed. So what should happen to a piece whose ACK never came? The answer is simple: send it again.
Sending Again When Nothing Comes Back
The second habit is retransmission. If the sender waits for a set time and still receives no ACK for some piece, it assumes that piece was lost on the way and sends exactly the same piece again.
The receiver gets the resent piece and this time returns an ACK. Filling in the missing pieces like this, in the end nothing is missing.
Tap the two empty slots whose acknowledgment (ACK) never came back to resend those pieces. When a resent piece arrives, its slot is filled.
Thanks to retransmission, no pieces are missing anymore; every one of them is now in the receiver's hands.
One thing remains, though. Because the pieces crossed by separate routes, they arrived in a jumble: piece 5 may have come before piece 2. How is the order put right?
Putting Things in Order by Number
The third habit is ordering. TCP sends each piece with a number: 1, 2, 3, and so on.
It does not matter if the arrival order is mixed up, because the receiver looks at the numbers and lines the pieces up from the smallest. Even if piece 5 arrives first, it leaves a space for piece 2 and waits, and once every number is filled in, the original message comes back exactly as it was.
Real TCP numbers the data by byte position rather than by piece, but the idea is the same.
Tap the jumbled pieces in number order (1, 2, 3, 4) to line them up. Tap the wrong one and it tells you to tap the next number; get them all and the original message comes back.
Lined up by number, the jumbled pieces fit back into the original message. What was missing was received again and filled in, and the order was put right by number.
To the person receiving it, it looks as if no packet was ever lost or swapped. TCP quietly did all that work behind the scenes.
Summing Up
In one line: packets can go missing or arrive out of order. TCP sends an acknowledgment (ACK) when something arrives, sends again when nothing comes back (retransmission), and puts things in order by number.
So the receiver always gets everything, nothing missing and in order. Reliability over speed: that is TCP's promise.
Each press of the button reveals one more key point. (loss/jumble → ACK on arrival → resend if none → order by number) Once all four have appeared, the review is done.
For safety's sake, TCP acknowledges, resends, and lines things up, which means a little more waiting.
Sometimes that waiting is a waste, though: in voice calls or games, for instance, being fast matters more than losing a little. The next lesson is about a way of sending that skips the acknowledgments and goes fast.