Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Distributed Systems

How does TCP work on bad Wi-Fi?

Bad Wi-Fi drops data all day, yet downloads still finish. Here is how TCP pulls that off.

Derpx069 Nov · 4 min read
Contents
What does packet loss actually look like?How do two computers start a conversation?How does TCP know something is missing?What happens when a packet is lost?Why doesn't TCP just resend everything faster?Is slow start really slow?What does TCP do after a drop?The cheat sheetSources
0% read · 4 min leftBack to top ↑
On this page0%
Contents
What does packet loss actually look like?How do two computers start a conversation?How does TCP know something is missing?What happens when a packet is lost?Why doesn't TCP just resend everything faster?Is slow start really slow?What does TCP do after a drop?The cheat sheetSources

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.

What does packet loss actually look like?

Press play and watch packets travel from your phone to the server. Every third one gets lost at the router.

Your phone
Wi-Fi router
×
Server
Demo setting: every 3rd packet is lost on the second link. Real Wi-Fi loss is messier.

The lost packets just vanish. Nothing tells the phone. Something has to notice, and that something is TCP.

Think of a post office

Letters get numbered. If letter 4 never shows up, the receiver can see the gap and ask for it again. TCP does this job for data.

But before it can notice anything, both sides need to agree to talk.

How do two computers start a conversation?

They use a quick greeting called the three-way handshake. Click Next and watch the three messages.

Your phone
Server

Phone sends SYN (short for synchronize, meaning: I want to talk)

Step 1 of 3
Three messages. Each side also picks a starting sequence number here.

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?

How does TCP know something is 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.

1Sender sends bytes 1 to 1000
2Receiver replies: next wanted is 1001
3Sender sends 1001 onwards
The ack always points at the next missing byte.

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?

What happens when a packet is lost?

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.

Receiver's view

The receiver keeps asking for byte 1001, because something is missing.

Sender's view

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.

Why doesn't TCP just resend everything faster?

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.

Start: tiny window, a few segments
Slow start: window doubles every round trip
Congestion avoidance: grow by one segment per round trip
Loss: cut back and try again
Careful at the start, gentle once the network is busy.

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.

Is slow start really slow?

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.

small segments (up to 1095 bytes)4 segments
medium (1096 to 2190 bytes)3 segments
large (over 2190 bytes)2 segments
Initial window from RFC 5681. Bigger segments, fewer of them at the start.

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?

What does TCP do after a drop?

A drop is a sign that the network is struggling. How far TCP backs off depends on how it noticed.

  1. Fast retransmit (3 duplicate acks): RFC 5681 sets ssthresh to half of what was in flight, but not below two segments.
  2. Then it resends the lost piece and keeps going from that halved level, without starting over.
  3. Timeout (total silence): more serious. The window drops to one full segment and slow start begins again, up to the new ssthresh.

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.

Before the dropPacket lost: window was big, say 20 segments
→
After fast retransmitWindow cut to about half, then grows slowly again

The window climbs, drops, and climbs again. That sawtooth is how TCP keeps finding out what your Wi-Fi can handle.

The cheat sheet

ProblemTCP's fix
Other side not readyThree-way handshake
Data arrives out of orderSequence numbers on every byte
Data goes missingAcks, timer, fast retransmit
Network too busyCongestion window shrinks after loss
Sender too fast for the receiverA 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.

Key takeaways
  • TCP numbers every byte, and the receiver's acks tell which byte it wants next.
  • Lost data is found by a timer or by three duplicate acks, then resent.
  • A congestion window limits how much is in flight, grows on success and shrinks on loss.
  • Flow control protects the receiver, congestion control protects the network. Different jobs.

Sources

  • RFC 9293: Transmission Control Protocol (TCP)
  • RFC 5681: TCP Congestion Control
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Distributed Systems · 6 minHow does your computer know the time? (And why it can be wrong)Distributed Systems · 4 minWhat are CRDTs? How shared documents stay in syncDistributed Systems · 3 minWhy mobile apps are hard: your phone is on bad internet
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)