← All posts
TCP/IP

The TCP Receive Window and Window Scaling: How TCP Manages Data in Flight

The TCP Receive Window and Window Scaling: How TCP Manages Data in Flight

Every TCP segment you capture carries a small number called the window. It is the receiver telling the sender, "this is how much more data I can buffer right now." Get it wrong, or let a middlebox mangle it, and a fast link behaves like a slow one. This post covers the receive window, why the original 16-bit field became a bottleneck, how window scaling fixes it, and how to read all of it in a packet capture.

What the receive window actually is

The receive window (rwnd) is flow control. The receiver advertises, in every ACK, how many bytes beyond the acknowledged sequence number it is willing to accept. The sender must keep its unacknowledged data within that limit. It is about protecting the receiver's buffer, not the network. Protecting the network is the job of the congestion window (cwnd), and the sender is limited by the smaller of the two:

bytes in flight <= min(cwnd, rwnd)

So if a transfer is slow, one of three things is usually true: cwnd is small (loss or slow start), rwnd is small (the receiver or its configuration), or the application is not supplying data. Reading the window field in a capture tells you whether the second case applies. The window is defined in RFC 9293, which obsoletes the original RFC 793.

The 16-bit limit and the bandwidth-delay product

The window field in the TCP header is 16 bits, so the largest value you can advertise without help is 65,535 bytes. For the header layout, see TCP header: ports, sequence numbers and flags.

A sender can have at most one window of data in flight per round trip. That puts a ceiling on throughput of roughly window divided by RTT. A quick calculation (arithmetic, not a measurement):

window = 65,535 bytes, RTT = 50 ms
max throughput ~ 65,535 / 0.05 = 1,310,700 bytes/s ~ 10.5 Mbit/s

That is true even if the link is 1 Gbit/s. To fill a pipe you need a window at least as large as the bandwidth-delay product (BDP), which is link rate times RTT:

BDP = (1,000,000,000 / 8) bytes/s x 0.05 s = 6,250,000 bytes (~6.25 MB)

On a LAN with a sub-millisecond RTT, 64 KB is plenty. Over a WAN, a cloud interconnect or a long-haul data-center-interconnect link, it is not.

Window scaling: RFC 7323

RFC 7323 (which replaced RFC 1323) defines the Window Scale option. It does not change the 16-bit field. Instead, both sides agree on a shift count, and the real window is the field value shifted left by that many bits:

effective window = window field x 2^shift

Key rules worth remembering:

  • The option (kind 3, length 3) is only valid in SYN and SYN-ACK segments. It is sent once, during the handshake. See the three-way handshake for where those segments fit.

  • Scaling is only in effect if both sides include the option. If only one side sends it, neither side scales.

  • The shift count is per direction. Each side announces the shift it will apply to the windows it advertises, and the two values can differ.

  • The window field inside a SYN segment itself is never scaled.

  • The maximum shift is 14, which gives a maximum window of 65,535 x 2^14 = 1,073,725,440 bytes, just under 1 GiB.

Each shift step trades granularity for range. With a shift of 7, the window moves in 128-byte steps, which is fine at those sizes.

Seeing it in Wireshark

Capture the whole connection, including the SYN. Open the SYN and expand TCP, then Options. You should see an entry like this (illustrative output):

Options: (20 bytes), Maximum segment size, SACK permitted, Timestamps,
         No-Operation (NOP), Window scale
    Window scale: 7 (multiply by 128)

Wireshark exposes two useful fields on every later segment:

tcp.window_size_value   the raw 16-bit field as on the wire
tcp.window_size         the calculated value after applying the scale
tcp.window_size_scalefactor   the multiplier Wireshark is using

Try these display filters:

tcp.options.wscale.shift                 # SYN / SYN-ACK segments carrying the option
tcp.analysis.zero_window                 # receiver advertised a window of 0
tcp.analysis.window_full                 # sender filled the advertised window
tcp.analysis.window_update               # pure ACK that only changes the window

A common trap: if you start the capture after the connection was established, Wireshark never saw the scale option, so it shows the raw value and the calculated window looks tiny. A flow that seems stuck at a few hundred bytes of window may simply be a capture that missed the SYN. (Wireshark has a preference for guessing scaling on mid-stream captures, but treat its numbers as approximate.)

Reading window behavior over time

Three patterns come up again and again.

Window full. The sender has sent as much as the receiver allows and is waiting for ACKs. If this flag shows up constantly while the link is underused, the receive window, not the network, is the limiter. A larger receive buffer on the receiving host is the fix.

Zero window. The receiver's buffer is full, usually because the application is not reading fast enough. The receiver advertises a window of 0 and the sender stops. The sender then sends small window probes, and the receiver sends a window update when space frees up. A burst of zero-window events points at the receiving application or disk, not at the network. The sender's probing is driven by the persist timer, not by TCP keepalive; the two are easy to confuse.

Small, constant window. A window pinned at an odd small value from the start of the flow, on a link where you expect more, suggests scaling did not negotiate. Compare the SYN and SYN-ACK: if one lacks the Window scale option, that is your answer.

Why scaling fails in real networks

Because the option is negotiated only in the handshake, anything that rewrites or drops the SYN options can quietly disable it. Typical causes include older or poorly configured firewalls and load balancers that strip unknown TCP options, and proxies that terminate and re-originate the connection with different settings. Symptoms are a connection that works but never exceeds a few megabits across a long path. The fix is to find the device that modifies the SYN, by capturing on both sides of it and comparing the options.

A related caution: a firewall that tracks sequence numbers can drop packets that fall outside the window it computed. If it ignores the scale factor, it will compute a window far too small and discard valid data. Capturing before and after the device again shows where the segments disappear.

Tuning on Linux (illustrative)

On Linux, window scaling is controlled by a sysctl and is on by default on modern kernels. Receive buffer sizing is automatic by default. The commands below are illustrative; check your distribution's kernel documentation before changing production hosts.

# is scaling enabled?
sysctl net.ipv4.tcp_window_scaling

# min / default / max receive buffer in bytes
sysctl net.ipv4.tcp_rmem

# receive buffer auto-tuning (1 = on)
sysctl net.ipv4.tcp_moderate_rcvbuf

# example of raising the ceiling for a high-BDP path
sudo sysctl -w net.ipv4.tcp_rmem="4096 131072 16777216"
sudo sysctl -w net.core.rmem_max=16777216   # caps SO_RCVBUF set by applications; autotuning is capped by the third tcp_rmem value

The advertised window is derived from the receive buffer, and the kernel reserves part of that buffer for overhead, so the window you see on the wire is smaller than the raw buffer value. Size buffers for the BDP you calculated earlier, then confirm with a capture rather than trusting the setting. Do not expect a bigger buffer to help if the sender's cwnd or the application is the real limit.

A short troubleshooting checklist

  1. Capture the full connection, SYN included, ideally at both ends.

  2. Check the SYN and SYN-ACK for the Window scale option in both directions.

  3. Compute the BDP for the path and compare it with the calculated window.

  4. Filter for tcp.analysis.zero_window and tcp.analysis.window_full to see who is the bottleneck, the receiver or the network.

  5. If the window is fine but throughput is not, look at loss and retransmissions next. Reliability and congestion are covered in what TCP reliability means.

Takeaways

The receive window is flow control: it limits how much unacknowledged data a sender can have in flight to what the receiver can buffer. The 16-bit field caps it at 65,535 bytes, which is far too small for high bandwidth-delay paths. Window scaling, negotiated once in the SYN exchange, multiplies the field by up to 2^14. When throughput disappoints, check the handshake options first, then the window behavior over time.

Comments (0)

Please sign in to comment.

  • Be the first to comment.