# TCP Flow Control
## What is TCP Flow Control
TCP flow control is a mechanism that prevents the sender from transmitting data faster than the receiver can process and store it. Every TCP receiver has a finite amount of buffer memory to hold incoming data before the application processes it. If the sender transmits faster than the receiver can consume data from its buffer, the buffer overflows and data is lost. Flow control allows the receiver to communicate its available buffer space to the sender so the sender can regulate its transmission rate accordingly.
## Receive Window
The receive window, also called rwnd, is the flow control mechanism in TCP. Each TCP segment contains a 16-bit window size field in the header. The receiver sets this field to indicate how many bytes of data it is prepared to accept from the sender. The sender must not have more unacknowledged data outstanding than the size of the receive window. When the receiver's buffer fills up, it reduces the window size it advertises. When the buffer empties as the application reads data, the receiver advertises a larger window.
## Window Size Operation
When the receiver's buffer is 65,535 bytes and empty, it advertises a window of 65,535 to the sender. As the sender sends data and the receiver's buffer fills, the receiver reduces the window it advertises. For example, after receiving 20,000 bytes that the application has not yet read, the receive window becomes 45,535. The sender limits the amount of unacknowledged data it has outstanding to 45,535 bytes. As the application reads data from the buffer, the receiver advertises larger windows again, allowing the sender to send more.
## Zero Window
When the receiver's buffer is completely full, it advertises a receive window of zero. The sender must stop transmitting when the window is zero. However, the sender needs to periodically probe to find out when the receiver's buffer has space again. The sender sends small window probe segments at intervals. If the receiver's buffer has freed up, it responds with an updated window size greater than zero.
## Window Scaling
The original TCP specification uses a 16-bit window size field, limiting the maximum window to 65,535 bytes. This is insufficient for high-bandwidth, high-latency connections such as intercontinental fiber links, where large windows are needed to keep the link fully utilized. The TCP window scale option, defined in RFC 1323, allows the window size to be scaled by a factor of up to 2 to the power of 14, effectively increasing the maximum window to about 1 gigabyte.Back to Subject