Skip to content

Flow Control in TCP (rwnd) ​

Flow control ensures the sender doesn't overwhelm the receiver by sending data faster than the receiver can process it.

The Problem ​

Fast Sender ---- too much data ----> Slow Receiver
                (buffer overflow → packets dropped)

Solution — Receive Window (rwnd) ​

  • Receiver tells sender how much buffer space is available.
  • This is the rwnd (Receive Window) field in the TCP header.
  • Sender must not have more than rwnd bytes of unacknowledged data in flight at any time.

How rwnd Works ​

Receiver Buffer = 4000 bytes

Step 1: Receiver → "rwnd = 4000" (I can accept 4000 bytes)
Step 2: Sender sends 4000 bytes
Step 3: Receiver processes 2000 bytes → "rwnd = 2000"
Step 4: Sender sends only 2000 more bytes
Step 5: Receiver processes all → "rwnd = 4000" again

Sliding Window Mechanism ​

  • TCP uses a sliding window to allow multiple packets in flight without waiting for each ACK.
  • Window slides forward as ACKs are received.
  • Allows continuous data flow without stop-and-wait.
  • Window size = rwnd (adjusted dynamically).
Sequence: 1  2  3  4  5  6  7  8  9  10
          [ sent ][ in flight ][ not sent ]
                ↑ window slides as ACKs arrive

Normal Operation ​

Sender                                Receiver
  |------- 1000 bytes -------------->|  rwnd = 4000
  |------- 1000 bytes -------------->|  rwnd = 3000
  |------- 1000 bytes -------------->|  rwnd = 2000
  |<------ ACK, rwnd=4000 ------------|  (receiver processed data)
  |------- 1000 bytes -------------->|

Zero Window (Receiver Buffer Full) ​

Sender                                Receiver
  |------- data --------------------->|
  |<------ ACK, rwnd=0 ----------------|  "STOP! Buffer full"
  |         (sender pauses)            |
  |<------ ACK, rwnd=2000 -------------|  "OK resume now"
  |------- data --------------------->|

When rwnd = 0, sender stops transmitting. Sender sends periodic Window Probe packets to check if window opened.

rwnd in TCP Header ​

  • Window field = rwnd — 16 bits → max 65,535 bytes.
  • Can be scaled using TCP Window Scaling option (up to 1GB).

Flow Control vs Congestion Control ​

Flow ControlCongestion Control
ProblemReceiver too slowNetwork too congested
Controlled byrwnd (receiver)cwnd (sender)
Who decidesReceiverSender
MechanismSliding windowSlow start, AIMD
GoalProtect receiver bufferProtect network
Effective Window = min(rwnd, cwnd)

rwnd = receiver's available buffer (flow control)
cwnd = congestion window (congestion control)
Actual data in flight ≤ min(rwnd, cwnd)

Silly Window Syndrome — inefficiency when tiny rwnd causes tiny packets → solved by Nagle's Algorithm.