Bad Wi-Fi drops data all day, yet downloads still finish. Here is how TCP pulls that off.
Bad Wi-Fi drops data all the time, and yet your downloads finish and your files arrive intact. That is not luck. It is TCP (Transmission Control Protocol), the set of rules under most of the web. It quietly looks after every connection.
The internet can lose, delay or shuffle the small chunks of data (called packets) that it carries. It never reports a problem. TCP's job is to turn that mess into one clean stream of bytes.
First, let's watch the mess happen.
Press play and watch packets travel from your phone to the server. Every third one gets lost at the router.
The lost packets just vanish. Nothing tells the phone. Something has to notice, and that something is TCP.
But before it can notice anything, both sides need to agree to talk.
They use a quick greeting called the three-way handshake. Click Next and watch the three messages.
Phone sends SYN (short for synchronize, meaning: I want to talk)
RFC 9293, the current official TCP spec, allows the middle two steps to be combined into one message. That is why there are three messages and not four.
Now the main trick: how does TCP know what went missing?
It numbers the data. Not the messages, the bytes. Every byte has its own sequence number, like numbered seats in a theater.
The acknowledgment number tells the sender which byte the receiver wants next. Acks are cumulative, so an ack of X means every byte before X has arrived.
The sequence number field is 32 bits wide, and the starting number is not always zero. The spec asks for it to be hard for outsiders to guess. That stops attackers from slipping fake data into your connection.
So what happens when a gap shows up?
Say the receiver gets bytes up to 1000, then a chunk after 2000, but nothing in between. It cannot ack past the gap. So it keeps sending the same ack for 1001, again and again.
The receiver keeps asking for byte 1001, because something is missing.
The sender sees the same ack repeat, which is a sign that something was lost.
The sender has two ways to notice. One is a timer: if no ack arrives in time, send the data again. This wait is the retransmission timeout. RFC 9293 requires it to be worked out on the fly, so it adapts to how slow your network is right now.
The faster way comes from RFC 5681. Three duplicate acks in a row mean a segment was probably lost. The sender resends right away instead of waiting. That is fast retransmit.
Lost data gets resent. But if resending were all TCP did, it would make things worse.
Because a jammed network needs less traffic, not more. Think of a narrow hallway. If everyone pushes harder, nobody gets through.
So TCP keeps a number called the congestion window (cwnd). It is how much data the sender may have "in flight" (sent but not acked yet). It starts small and carefully tests how much the network can take.
A segment is one TCP-sized chunk of data. A round trip (RTT) is the time for a message to go and the reply to come back.
A quick note on the name before moving on.
Not really. Slow start begins small, then the window grows with every ack. That works out to roughly doubling each round trip. RFC 5681 sets the starting window by segment size.
It keeps going until the window reaches ssthresh (slow start threshold). Then TCP switches to congestion avoidance, growing about one segment per round trip. It is still growing, just more carefully.
And when a drop does happen?
A drop is a sign that the network is struggling. How far TCP backs off depends on how it noticed.
The reason: three duplicate acks mean some packets still get through, so the network is hurt, not dead. A timeout means nothing is coming back, so TCP restarts from the bottom.
The window climbs, drops, and climbs again. That sawtooth is how TCP keeps finding out what your Wi-Fi can handle.
| Problem | TCP's fix |
|---|---|
| Other side not ready | Three-way handshake |
| Data arrives out of order | Sequence numbers on every byte |
| Data goes missing | Acks, timer, fast retransmit |
| Network too busy | Congestion window shrinks after loss |
| Sender too fast for the receiver | A separate receive window (flow control) |
That last row often gets mixed up with congestion control. Flow control protects the receiver. Congestion control protects the network in between.