← All chapters
Chapter 18· 8 min read · illustrated

TCP Flow Control

The sliding window that stops a fast sender from drowning a slow receiver

A fast server can produce data far quicker than a slow client can consume it. Flow control is TCP’s mechanism to keep the sender from overflowing the receiver’s buffer — using a value called the window.

Careful: flow control protects the receiver, not the network. Protecting the network is congestion control, the next chapter.

01

The problem

The receiver has a limited buffer where incoming data waits to be read by the application. If the sender pushes data faster than the app reads it, that buffer fills up and overflows — and data is lost. Flow control prevents this.

Tap to enlarge
02

The receive window (rwnd)

The receiver tracks how much free space is left in its buffer and calls it the receive window (rwnd). This number is the maximum amount of unacknowledged data the sender is allowed to have in flight at once.

Tap to enlarge
03

Advertised in every ACK

The receiver advertises its current window in the Window field of every segment it sends back. So with each ACK the sender learns exactly how much more it may send. It must never exceed the advertised window.

Tap to enlarge
04

The sliding window

Picture the byte stream divided into: bytes sent and acknowledged, bytes sent but not yet acknowledged (in flight), bytes that may be sent now, and bytes that must wait. As ACKs arrive, the window slides to the right, letting new data be sent. Hence "sliding window".

Tap to enlarge
05

Window scaling

The window field is only 16 bits, capping it at 64 KB — too small for modern fast, long-distance links. The window scale option multiplies the window by a factor negotiated in the handshake, allowing much larger windows so fast links can stay full.

Tap to enlarge
06

Zero window = pause

If the receiver’s buffer is completely full, it advertises Window = 0, telling the sender to stop. The sender periodically sends tiny "window probes" to ask if space has opened up, and resumes once the receiver advertises a non-zero window again.

Tap to enlarge
07

Flow ≠ congestion

Do not confuse them: Flow control protects the RECEIVER (its buffer). Congestion control protects the NETWORK (the links in between). Same goal of smooth delivery, different bottleneck — congestion control is next.

Tap to enlarge