4.3.21 · D1Computer Networks

Foundations — TCP flow control — sliding window, receive buffer

1,773 words8 min readBack to topic

This page assumes nothing. Before you can read the parent note TCP flow control, you need a small toolkit of ideas. We build each from the ground up, in an order where every new thing rests on the last.


0 · What is a "byte" and a "byte stream"?

Figure — TCP flow control — sliding window, receive buffer

Look at the figure: each little box is one byte, and the number under it is that byte's fixed position. This numbering is the secret that makes everything else work — because now any pointer is just a number saying "up to here."

Why does the topic need this? Because every symbol in the parent note (LastByteSent, LastByteRcvd, …) is nothing more than a number pointing at one position on this tape. Master the tape and the symbols become obvious.


1 · Sender and receiver

Picture a person pouring water down a hose (sender) into a friend's cup (receiver). We will keep coming back to this picture.


2 · The receive buffer — a waiting room for bytes

Figure — TCP flow control — sliding window, receive buffer

Look at the figure: the box is the buffer. Bytes flow in from the left (from the network) and are pulled out on the right (by the program). The red segment is the part currently occupied. The topic exists entirely to keep that red part from ever filling the whole box.

Why the topic needs it: flow control is only about protecting this one buffer. Nothing about the network in between — that is a different mechanism (see Buffer overflow & packet loss and TCP congestion control — cwnd, AIMD).


3 · Two pointers on the receiver's side

Now that bytes are numbered (Section 0) and wait in a buffer (Section 2), we need to say where the buffer starts and ends on the tape. That takes exactly two numbers.

Why subtraction gives a count: if arrivals go up to seat and departures up to seat , then seats are occupied — that's bytes.


4 · The receive window rwnd — announced free room

Why the topic needs it: this single number is the brake pedal. When it's large, the sender may pour fast; when it hits , the sender must stop.


5 · Two pointers on the sender's side + "in-flight"

The receiver had two pointers; the sender needs two of its own to track what it has launched.

Figure — TCP flow control — sliding window, receive buffer

Look at the figure: on the numbered tape, everything up to LastByteAcked is done and confirmed. The red stretch between LastByteAcked and LastByteSent is in-flight — launched, fate unknown. Bytes past LastByteSent are not sent yet.


6 · Putting it together — the one inequality

Now every symbol is earned, and the whole parent topic collapses to a single line:

And the practical question "how many more may I send right now?": Free room, minus seats already reserved by in-flight bytes.


7 · One more symbol you'll meet: min(rwnd, cwnd) and 2^s

Two small notations appear later in the parent note. Meet them now so they never surprise you.


Prerequisite map

Numbered byte stream

Receive buffer capacity

Receiver pointers Rcvd and Read

Sender pointers Sent and Acked

Occupancy = Rcvd minus Read

In-flight = Sent minus Acked

rwnd = Buffer minus Occupancy

Sliding window rule

Read top to bottom: the numbered stream lets us define pointers; pointers give occupancy and in-flight; buffer size minus occupancy gives rwnd; rwnd versus in-flight gives the rule. Every arrow is a "you need this before that."


Equipment checklist

Test yourself — you're ready for the parent note when each answer comes instantly.

What is a byte stream in TCP's view?
One endless numbered tape of bytes (), each with a fixed position; pointers are just positions on it.
What is the receive buffer?
A fixed-size waiting room in the receiver's memory holding arrived bytes until the app reads them.
What do LastByteRcvd and LastByteRead mean?
Highest byte accepted into the buffer, and highest byte the app has consumed.
How do you compute buffer occupancy?
LastByteRcvd − LastByteRead — arrivals minus departures.
What is rwnd and its formula?
The announced free room: RcvBuffer − (LastByteRcvd − LastByteRead).
What do LastByteSent and LastByteAcked mean?
Highest byte pushed into the network, and highest byte the receiver confirmed.
What are in-flight bytes?
Sent but not yet acknowledged: LastByteSent − LastByteAcked — reserved seats in the buffer.
State the sliding-window rule in one line.
LastByteSent − LastByteAcked ≤ rwnd (in-flight ≤ announced free room).
How many more bytes may the sender transmit right now?
rwnd − (LastByteSent − LastByteAcked).
What does min(rwnd, cwnd) express?
The sender obeys the smaller of the receiver's limit and the network's limit.
What does 2^s do in window scaling?
Multiplies the 16-bit announced window (max 65535) by a power of two to allow much larger windows.

Connections