Transport Layer — Interactive Walkthrough

Companion to the "Transport Layer" note in the Networking Math and Lookups series. Compute a real TCP checksum, see sequence-number wraparound, watch RTT estimation settle, and drive AIMD congestion control step by step.

1. TCP Checksum Integrity Check

Type a message. It's split into 16-bit words, summed with one's-complement addition (folding any overflow back in), then inverted to produce the checksum — the exact algorithm TCP runs on every segment.

Checksum:

Now simulate the message travelling across a noisy link. The receiver recomputes the checksum over what it actually received and compares it to the checksum the sender attached — a mismatch means corruption.

2. Sequence Number Wraparound

TCP sequence numbers are 32-bit and wrap around after 2^32 - 1. "Is A ahead of B?" has to be answered with modular arithmetic, not a plain numeric comparison — the circle below always places B at the top and shows how far forward you'd have to travel to reach A.

3. RTT Estimation (EWMA)

TCP estimates round-trip time with an exponentially weighted moving average, so recent samples matter more than old ones but no single noisy sample swings the estimate wildly. Add sample RTTs one at a time and watch the estimate settle.

Estimated RTT
Samples added
Estimated RTT (smoothed) Raw sample RTT

4. AIMD Congestion Window

TCP grows its congestion window by a small fixed amount on every round trip with no loss (additive increase), and cuts it in half the instant it detects loss (multiplicative decrease) — the classic sawtooth. Step through rounds yourself, or let it auto-run.

Congestion window
Round
Window size Loss detected (window halved)