CS Atlas GATE 2027
Computer Networks course
0 / 90 complete

Computer Networks/Phase 4 · Transport Layer (TCP)

Lesson 4.3.3 · Item 69 of 90

TCP flow control (rwnd), sequence wrap-around time & window scaling

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. In the 20-byte TCP header, how many bits wide is the Window Size field, and what is the largest integer it can represent directly?
    Stuck? Peek at 4.3.2 TCP 3-way handshake, connection termination & state machine
    • 3-way handshake: SYN(seq=x) → SYN+ACK(seq=y, ack=x+1) → ACK(seq=x+1, ack=y+1).
    • Seq consumption: SYN = +1, FIN = +1, Pure ACK = 0, Data(L) = +L (full connection advances by D + 2).
    • Teardown states: Active closer goes FIN-WAIT-1 → FIN-WAIT-2 → TIME-WAIT (2·MSL) → CLOSED; Passive closer goes CLOSE-WAIT (half-close) → LAST-ACK → CLOSED.

    Read lesson 4.3.2

  2. How many distinct byte sequence numbers exist in TCP’s 32-bit Sequence Number field?
    Stuck? Peek at 4.2.2 Sliding window protocols, pipelining & k-bit sequence numbers
    • Sliding-window utilisation: η = min(1, N / (1 + 2a)); full utilisation at N = ⌈1 + 2a⌉.
    • k-bit sequence space: 0 .. 2ᵏ − 1 (2ᵏ numbers); universal bound: Ws + Wr ≤ 2ᵏ.

    Read lesson 4.2.2

  3. What is the Bandwidth-Delay Product (in bytes) of a 1 Gbps link with RTT = 100 ms?
    Stuck? Peek at 1.3.3 RTT, bandwidth-delay product, utilisation and a = Tp/Tt
    • RTT = 2·Tp for tiny signals (add Tt / queuing if stated).
    • BDP = B × Tp bits in flight; B × RTT before any reply.
    • a = Tp / Tt.
    • Send-and-wait: U = Tt/(Tt + 2Tp) = 1/(1 + 2a); throughput = U·B.
    • To keep the link busy: about 1 + 2a units in flight.

    Read lesson 1.3.3

The Hook

What happens if a fast server sends data at 1 Gbps to a smartphone whose application reads data slowly from its receive buffer? Without feedback, the smartphone's memory buffer would overflow in milliseconds!

TCP Flow Control solves this: in every ACK segment, the receiver advertises its current free buffer space in the 16-bit Receive Window (rwnd) field. In this lesson we also solve two famous GATE numericals: how fast do 32-bit sequence numbers wrap around, and how does Window Scaling break past the 64 KB limit?

Predict First

Suppose the receiver's buffer fills up completely, so it sends an ACK with rwnd = 0 (stopping the sender). Later, the receiving app reads data and the receiver sends a pure ACK with rwnd = 4000 — but remember from 4.3.2 that pure ACKs are not acknowledged, and suppose that rwnd = 4000 ACK is lost on the link! Why don't both sides wait for each other forever in a permanent deadlock?

,

Because when a TCP sender receives rwnd = 0, it starts a Persist Timer! Whenever the persist timer expires, the sender transmits a tiny 1-byte Zero-Window Probe segment, forcing the receiver to reply with an ACK carrying its current rwnd!

Core Concept

Receiver Buffer & the Advertised Window (rwnd)

Suppose the receiver allocates a receive buffer of size RcvBuffer bytes. At any instant, some bytes have arrived from the network and are sitting in the buffer waiting for the receiving application to read them:

TCP Flow-Control Equations:
• rwnd = RcvBuffer − (LastByteRcvd − LastByteRead) (free space remaining in receiver buffer).
• Receiver places rwnd in the 16-bit Window Size field of every outgoing segment.
• Sender guarantees: LastByteSent − LastByteAcked ≤ rwnd (bytes in flight never exceed rwnd).

Zero Window & Persist Timer: When rwnd = 0, the sender stops normal transmission and runs a Persist Timer, periodically sending a 1-byte Zero-Window Probe so a lost non-zero window update never causes deadlock.

Already read by App0–1499
Buffered unread (2500 B)1500–3999
Free space rwnd = 7500 B4000–11499
011499
Inside a 10,000-byte receive buffer (offsets 1500..11500): 2500 B are unread, so advertised rwnd = 10,000 − 2500 = 7500 B.

32-Bit Sequence Number Wrap-Around Time

Because the TCP Sequence Number field is 32 bits, there are 2³² = 4,294,967,296 bytes before sequence numbers wrap back to 0. If a sender transmits continuously at data rate B bits/second (which is B / 8 bytes/second):

Sequence Number Wrap-Around Time:
T_wrap = (2³² bytes) / (B / 8 bytes/sec) = (2³² × 8) / B seconds = 2³⁵ / B seconds.

To prevent an old delayed segment from colliding with a new segment of the same sequence number after wrap-around, T_wrap must be strictly greater than the Maximum Segment Lifetime (MSL) (or TCP must add the 32-bit PAWS — Protection Against Wrapped Sequence numbers — timestamp option on multi-Gbps links).

Link Data Rate BBytes/sec (B / 8)Wrap-Around Time T_wrap = 2³⁵ / B
10 Mbps (10⁷ bps)1.25 × 10⁶ B/s3,435.97 seconds (≈ 57.3 minutes)
100 Mbps (10⁸ bps)1.25 × 10⁷ B/s343.60 seconds (≈ 5.7 minutes)
1 Gbps (10⁹ bps)1.25 × 10⁸ B/s34.36 seconds (less than a 60s MSL!)
10 Gbps (10¹⁰ bps)1.25 × 10⁹ B/s3.44 seconds (requires TCP Timestamps / PAWS!)
Memorise the benchmark: at 1 Gbps (10⁹ bps), 32-bit TCP sequence numbers wrap around in 34.36 seconds!

The 64 KB Window Limit & TCP Window Scaling Option

The TCP header's Window Size field is only 16 bits, so the largest window it can advertise directly is 2¹⁶ − 1 = 65,535 bytes (≈ 64 KB). On a 1 Gbps link with RTT = 100 ms, the Bandwidth-Delay Product is 12.5 MB — a 64 KB window would cap link utilisation at 64 KB / 12.5 MB ≈ 0.5%!

TCP Window Scale Option (RFC 7323):
Negotiated inside the SYN segments during the 3-way handshake, a shift count S ∈ {0, 1, …, 14} multiplies the 16-bit header window value by 2ˢ:
True rwnd = (Header Window Field) × 2ˢ (up to 65,535 × 2¹⁴ ≈ 1 GiB).
Without Window Scaling (S = 0)
Max rwnd = 65,535 bytes (2¹⁶ − 1). Throughput capped at 65,535 / RTT bytes/sec.
With Window Scaling (shift S ≤ 14)
True rwnd = HeaderWindow × 2ˢ. Max rwnd = 65,535 × 2¹⁴ ≈ 1.07 × 10⁹ bytes (≈ 1 GiB)!
How a 1-byte shift factor S in the SYN options expands the 16-bit window to 30 bits.

Putting it together

  • TCP flow control protects the receiver’s buffer by advertising free space rwnd in every ACK; a Persist Timer prevents deadlock when rwnd = 0.
  • The 32-bit byte sequence number wraps around in (2³² × 8) / B seconds (34.36 s at 1 Gbps).
  • The Window Scale option shifts the 16-bit window field left by up to 14 bits (× 2ˢ), expanding max rwnd from 64 KB to ~1 GiB.

Visual

Receiver Buffer (RcvBuffer)
Unread Data grows
rwnd = RcvBuffer − Unread
If rwnd == 0
Sender stops & starts Persist Timer
Persist Timer fires
1-byte Zero-Window Probe → gets fresh rwnd
TCP Flow Control and Persist Timer loop.

Worked Examples

Easy

Receiver B has a 10,000-byte receive buffer (currently empty). Sender A sends 4,000 bytes, which arrive at B, and the application at B reads 1,500 of those bytes. What value of rwnd does B advertise in its next ACK?

Show the full solution

Unread bytes still in buffer = 4,000 − 1,500 = 2,500 bytes.
Free space rwnd = 10,000 − 2,500 = 7,500 bytes.

Medium

Calculate the sequence-number wrap-around time (in seconds, to 2 decimal places) for a TCP connection operating at full capacity over a 1 Gbps (10⁹ bit/s) link.

Show the full solution

T_wrap = (2³² × 8 bits) / 10⁹ bit/s = 34,359,738,368 / 10⁹ ≈ 34.36 seconds.

GATE

During the 3-way handshake, a receiver negotiates a TCP Window Scale factor of S = 4. Later, during data transfer over a link with RTT = 40 ms, the receiver places the value 32,000 in its 16-bit TCP Window Size header field. What is the true advertised receive window in bytes, and what is the maximum throughput (in Mbps) allowed by flow control?

Show the full solution

1) True receive window: rwnd = 32,000 × 2⁴ = 32,000 × 16 = 512,000 bytes.
2) In one RTT = 40 ms = 0.04 s, the sender can send at most 512,000 bytes = 4,096,000 bits.
3) Max throughput = 4,096,000 bits / 0.04 s = 102.4 × 10⁶ bit/s = 102.4 Mbps.

GATE Traps

  • Bytes vs Bits in Wrap-Around Time! Each TCP sequence number counts 1 byte = 8 bits, so the total bits in one cycle is 2³² × 8 = 2³⁵ bits (students who forget the × 8 get 4.29 seconds instead of 34.36 seconds!).
  • Window Scale option can ONLY be sent in SYN segments! The scale shift S is fixed during the 3-way handshake and cannot be changed mid-connection.

Memory Hook

T_wrap = 2³² × 8 / B (34.36 s at 1 Gbps); rwnd = free buffer; Persist Timer pokes a Zero Window!

Connect the Dots

We now know how TCP numbers bytes, sets up connections, and controls flow with rwnd. Next question (4.3.4): How does a TCP sender know how many milliseconds to set its retransmission timeout (RTO) timer for when internet round-trip times fluctuate wildly?

Self-Test

  1. NAT

    A TCP connection transfers data continuously at a rate of 2 Gbps (2 × 10⁹ bits/sec). How many seconds (rounded to 2 decimal places) does it take for the 32-bit TCP sequence number space to wrap around?

    Write your answer before opening the key.

  2. NAT

    A TCP receiver has a total receive buffer of 64,000 bytes. Currently 14,000 bytes of unread data are sitting in the buffer. If the connection uses NO window scaling (S = 0), what value does the receiver place in the 16-bit Window Size field of its next ACK?

    Write your answer before opening the key.

  3. MCQ

    What is the purpose of the TCP Persist Timer?

    1. To measure the round-trip time of every segment.
    2. To close a connection after 2 × MSL in the TIME-WAIT state.
    3. To periodically send a 1-byte Zero-Window Probe when the receiver has advertised rwnd = 0, preventing deadlock if a subsequent non-zero window update ACK is lost.
    4. To double the transmission rate every RTT.
  4. NAT

    During the 3-way handshake, a TCP receiver advertises a Window Scale shift count of S = 3. Later, it sends an ACK with the 16-bit Window Size field set to 10,000. What is the actual receive window size (rwnd) in bytes?

    Write your answer before opening the key.

Rule Card

  • Flow control: rwnd = RcvBuffer − (LastByteRcvd − LastByteRead); sender keeps BytesInFlight ≤ rwnd.
  • Zero window (`rwnd = 0`): sender runs Persist Timer and sends 1-byte Zero-Window Probes.
  • Wrap-around time: T_wrap = (2³² × 8) / B seconds (34.36 s at 1 Gbps).
  • Window scaling: True rwnd = HeaderWindow × 2ˢ (S ≤ 14, negotiated in SYN).

Concept Ledger

  • rwnd (advertised receive window)
  • TCP flow control
  • zero window
  • persist timer and zero-window probe
  • wrap-around time = 2³²·8 / B
  • window scaling (shift ≤ 14)

Answer Vault

Try the questions first. Open when you are ready to check.

Warm-up answers

  1. 16 bits wide; max value = 2¹⁶ − 1 = 65,535 bytes.
  2. 2³² = 4,294,967,296 bytes (4 GiB).
  3. (10⁹ bit/s × 0.1 s) / 8 = 12,500,000 bytes (12.5 MB).

Self-test answers

  1. 17.17..17.19 — T_wrap = (2³² × 8) / (2 × 10⁹) = 34,359,738,368 / (2 × 10⁹) ≈ 17.18 seconds.
  2. 50000 — rwnd = RcvBuffer − Unread = 64,000 − 14,000 = 50,000 bytes.
  3. C — When rwnd = 0, the sender starts the Persist Timer and sends 1-byte probes on timeout so a lost window-update ACK cannot deadlock the connection.
    • A: That is RTT estimation.
    • B: That is the 2·MSL TIME-WAIT timer.
    • D: Persist timer only probes a zero receive window.
  4. 80000 — True rwnd = 10,000 × 2³ = 10,000 × 8 = 80,000 bytes.

Flashcards

  1. Formula for TCP 32-bit sequence number wrap-around time at link rate B bits/sec?
    Reveal answerT_wrap = (2³² × 8) / B seconds (≈ 34.36 seconds at 1 Gbps).
  2. What does a TCP sender do when it receives rwnd = 0?
    Reveal answerIt pauses normal data transmission and starts the Persist Timer, sending 1-byte Zero-Window Probes when the timer expires.
  3. If the TCP Window Size field is W and the Window Scale option shift is S, what is the true rwnd?
    Reveal answerW × 2ˢ bytes (where S ≤ 14 is negotiated in the SYN handshake).

Exam shortcuts

  • 1 Gbps Wrap-Around Benchmark: Memorise T_wrap(1 Gbps) = 34.36 s! Then for any rate X Gbps, just divide: T_wrap = 34.36 / X seconds (and for Y Mbps, 34,360 / Y seconds)! — solving any GATE wrap-around time question in 5 seconds without computing 2³⁵.
  • Max Flow-Control Throughput: Throughput_max = min(B, (rwnd in bits) / RTT). — questions giving rwnd and RTT and asking for throughput.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.