TL;DR
A fast sender can send data faster than a slow receiver can read it. The data then piles up in the receiver's memory until that memory is full, and the rest is lost. Flow control prevents this: the receiver tells the sender how much free buffer space it has, and the sender never has more data outstanding than that space allows. The rule protects the receiver. It says nothing about the network in between, which is the job of Congestion Control.
Builds on: Automatic Repeat Request · Leads to: Congestion Control
Where it's used
The TCP receive window. Every TCP segment carries a window field that states how many more bytes the receiver can accept. A laptop downloading a large file from a server receives the window in each acknowledgement, and the server never has more unacknowledged bytes in flight than that. The field is 16 bits wide, so without the window-scaling option it can express at most 65,535 bytes.
Ethernet PAUSE frames. A network switch whose output buffer is filling can send a PAUSE frame to the device on the other end of the cable, asking it to stop sending for a set time. The standard IEEE 802.3x, published in 1997, defines this link-level form of flow control, so a busy switch can slow its neighbours before its memory overflows.
Pipes and bounded queues. A program that writes into a Unix pipe blocks when the pipe's buffer is full, and continues only after the reading program has taken data out. The same idea is the core of the Producer-Consumer Problem: a buffer of fixed size makes the fast producer wait for the slow consumer.
How it works
A buffer is a fixed block of memory where arriving data waits until the program reads it. Its size is packets. The receiver's application reads packets from the buffer in order. The example uses , and sends numbered packets. The receiver's acknowledgements are cumulative, as in Automatic Repeat Request: an acknowledgement "next 5" means packets 1 to 4 arrived in order.
Start with an empty buffer, , and nothing read yet.
-
Advertise the room. The receiver has 4 free slots, so it tells the sender that it can accept 4 packets. The sender may have at most 4 packets outstanding. Check: the sender's allowance is the buffer size, because nothing is waiting to be read.
-
The sender fills the room. The sender transmits packets 1, 2, 3 and 4. All four arrive in order and wait in the buffer, because the application has not read any of them yet. The buffer is full. The receiver acknowledges "next 5" with window 0. Check: the sender must now stop, even though the network could carry more.
-
The application reads two packets. The program takes packets 1 and 2 out of the buffer. Two slots are free. The receiver sends a window update: "next 5, window 2". Check: the window reopened because the program read data, not because more data arrived.
-
The sender uses the new room. The sender transmits packets 5 and 6. The buffer now holds packets 3, 4, 5 and 6, which is full again. Check: the sender sent exactly the 2 packets the window allowed.
-
A slow reader closes the window again, then opens it. The program reads nothing for a while, and the receiver acknowledges with window 0. The sender waits holding packets 7 and 8. Then the program reads packets 3 and 4. Two slots are free, and the receiver sends "next 7, window 2". The sender transmits packets 7 and 8. Check: the sender was held back during the stall and resumed as soon as room appeared.
The plot shows the window the receiver advertised after each numbered step.
- advertised window (packets)
The math
Let be the buffer size in packets. Let be the highest packet number the application has read, and the highest packet number received in order, so the packets waiting in the buffer are . The receiver advertises the window . The sender's highest sent packet number must satisfy .
Because , the rule can also be written as . The sender may never be more than packets ahead of what the application has read. The receiver's memory is therefore never asked to hold more than packets.
Step 1 in symbols: the first allowance
Nothing has been read and nothing has arrived, so and . The sender may send up to .
Step 2 in symbols: the buffer fills
After packets 1 to 4 arrive, and . The window is . The sender's limit is , which it has reached.
Step 3 in symbols: the reader moves the edge
The program reads two packets, so . The window is . The limit is .
Step 4 in symbols: the check
The sender sends packets 5 and 6, so and . The window is , and the rule holds with equality.
Step 5 in symbols: the long run
The sender can only move its limit forward when the reader moves forward, because the limit is . Over a long transfer, the sender's position therefore cannot run ahead of the reader's position by more than . If the reader consumes packets per second, the sender's average rate also converges to once the buffer is full, however fast the link is. Ignoring the round-trip delay, which only shifts the timing, the rate is limited by the reader.
Worked examples
The buffer holds packets. So far the receiver has received packets 1 to 3, , and the program has read only packet 1, .
- The packets waiting in the buffer are .
- The window is .
- The sender may send up to .
- Interpretation: the sender may send one more packet, packet 4, and then must wait. The window is the free space, and it is one slot.
The buffer holds packets. The sender has a large file to send over a fast link, and the program reads 10 packets per second, so . Ignore the round-trip delay, which only shifts the timing.
- At the start the sender may send packets, so it sends a burst of 20.
- After 1 second the program has read 10 packets, so . The sender may now reach . It sends 10 more.
- After 10 seconds the program has read packets, so the sender may reach . In those 10 seconds it sent 120 packets, in total.
- Compute the average rate over those 10 seconds: packets per second. The initial burst of 20 inflates this figure. Each later second adds only the packets the program reads, which is 10, so the rate settles at packets per second once the burst is spent.
- Interpretation: the link can carry much more, but the sender's speed is set by how fast the program reads. The 20-packet buffer only lets the sender run ahead by a fixed amount.
A TCP receiver advertises a window of bytes, and the round-trip time is ms. The application reads data as fast as it arrives, so the window is never the limit on reading.
- The window allows bytes per round trip, so the window-limited rate is bytes per second.
- Convert to bits: bit/s, which is about 10.5 Mbit/s.
- Time a 10,000,000-byte download: seconds.
- Interpretation: on this path a plain 65,535-byte window caps the speed at about 10.5 Mbit/s, even on a much faster link. A larger window, enabled by window scaling, raises the cap.
Try it: the same 65,535-byte window, but with ms. What is the window-limited rate in Mbit/s?
Answer: bytes per second. Multiply by 8 to get bit/s, which is about 26.2 Mbit/s. The shorter round trip allows 2.5 times the rate, because the same window is sent more often.
Common mistakes and tradeoffs
It is tempting to think that flow control and Congestion Control are the same thing. In fact they protect different resources. Flow control keeps the sender from overflowing the receiver's buffer, and the receiver advertises that space. Congestion control keeps the sender from overflowing the network's queues, and the sender infers that from loss or delay, often by a rule such as AIMD. A real TCP sender obeys both limits and uses the smaller of the two.
It is tempting to think that a large window always makes a transfer faster. In fact the window only helps until either the receiver's reading speed or the link's capacity becomes the limit. Beyond that point, extra window only adds memory use.
It is tempting to think that a window of zero means the connection is dead. In fact it means the receiver is busy, and the sender must wait. TCP uses a persist timer to send occasional probes, so the sender learns when the window reopens even if the receiver's update was lost.
Use flow control when one end is much slower than the other, or when the receiver's memory is limited, as on a phone or an embedded device. It is not needed when the receiver can always consume data as fast as it arrives. Alternatives include credit-based schemes, where the receiver grants permission in units of messages rather than bytes, and pause frames, which act hop by hop instead of end to end, one link at a time as Protocol Layering describes. Each has the same goal: the sender's rate follows the receiver's capacity.
History
Early computer networks, such as the ARPANET in the 1970s, moved data between machines that often ran at very different speeds. A fast host could flood a slow one, and the slow one had no way to say stop except by dropping data and making the sender resend it. That wasted both link capacity and time.
The TCP specification, first published in 1981 as RFC 793, included a window field in each segment, so a receiver could state how much buffer it had. The idea was then carried into RFC 9293, the 2022 revision of TCP. Flow control became a standard part of reliable transport because it solved a problem that retransmission alone could not: resending a packet into a full buffer just loses it again.
Recap
- A receiver's buffer has a fixed size . Flow control makes the sender stay within packets of what the program has read.
- The receiver advertises a window , and the sender may send up to more.
- The window opens when the program reads and closes when the buffer fills, so the sender's speed follows the reader's speed.
- Flow control protects the receiver. Congestion Control protects the network, and a real sender obeys both.
What to read next: Congestion Control shows how a sender limits itself to the network's capacity, and Head-of-Line Blocking shows what happens when the in-order buffer holds back data that is already present.