AlgoPlusAlgoPlus
Learn/Networking
Lesson

TCP Congestion Control

TCP guesses the link's capacity with a congestion window: ramp up fast, probe gently, and halve on loss — the AIMD sawtooth.

9 min read Watch it move Build it

Nothing ever tells TCP how fast the network actually is — capacity changes constantly as other traffic comes and goes. So TCP *guesses*, and corrects. It keeps a congestion window (`cwnd`): the amount of unacknowledged data it's willing to have in flight. Send too little and the link sits idle; send too much and routers' queues overflow and drop packets. Congestion control is the feedback loop that hunts for the sweet spot.

Loss is the signal
TCP treats a dropped packet as the network saying *too fast*. It has no other speedometer — so the whole strategy is built around probing upward until something drops, then backing off.

Two growth phases

  1. 1Slow start — despite the name, this ramps *fast*: cwnd doubles every round trip (exponential), quickly filling an empty pipe.
  2. 2When cwnd reaches `ssthresh` (the slow-start threshold), TCP switches to congestion avoidance: cwnd grows by just one per round trip (linear), probing gently near the suspected limit.
  3. 3On a loss, TCP cuts cwnd sharply — classically halving it — and sets ssthresh to the new lower value before climbing again.

AIMD — the rule behind the sawtooth

The steady-state behavior is AIMD: *Additive Increase, Multiplicative Decrease*. Add a little when things are fine (+1 per RTT), but multiply down hard the instant a packet is lost (×½). Plotting cwnd over time draws a sawtooth: a gentle linear climb, a sudden drop, climb again — hovering right around the link's true capacity.

Why AIMD and not symmetric steps
Gentle increase plus aggressive decrease is what makes many flows sharing a link converge toward a fair, stable split. Cautious on the way up, decisive on the way down.
OperationTimeSpace
Slow start · exponential ramp-upcwnd doubles / RTT
Congestion avoidance · linear probingcwnd +1 / RTT
On loss · multiplicative decreasecwnd x 1/2
Check yourself
What does the 'AI' and 'MD' in AIMD mean for the congestion window?