TCP Internals Every Network Engineer Should Know
The three-way handshake is the least interesting part. Flow control, congestion control, retransmission, and windowing are where network problems actually live.
The certified-mail analogy
Imagine mailing a 500-page manuscript one page at a time. TCP (Transmission Control Protocol — the protocol that carries web pages, file transfers, and email) works like certified mail with return receipts: you number every page (sequence numbers), the recipient signs a receipt saying "I have everything up to page 214" (acknowledgments), and any page that never gets a receipt is mailed again (retransmission). On top of that, the recipient can say "slow down, my desk is full" (flow control), and you watch for signs the postal system itself is overloaded (congestion control).
Watch: the three-way handshake
Before any data flows, the two ends agree on starting page numbers. The handshake is three packets: SYN ("I'd like to talk, starting at sequence number 0"), SYN/ACK ("agreed — and I'll start at 0 too"), ACK ("confirmed"). Watch it run:
Sequence numbers are the protocol's memory
Each TCP segment (one TCP packet's worth of data) carries a sequence number (which byte this segment starts at — think "page number") and usually an acknowledgment number ("I have received every byte before this one" — the signed return receipt). Because ACKs are cumulative (one receipt covers everything before it), one ACK can confirm a whole batch — and a missing segment shows up as the receiver repeating the same ACK number: duplicate ACKs are the smoking gun of loss or reordering.
Flow control: the receive window
The receive window in each ACK says "I have room for this many bytes" — the recipient telling the sender how much desk space is free. The sender must never have more unacknowledged data in flight than the window. If the receiver is slow, the window shrinks — possibly to zero, freezing the connection. Watch the window breathe:
Congestion control reacts to the network
While flow control protects the receiver, congestion control protects the network — the sender watching for signs the postal system is overloaded and voluntarily slowing down. The sender maintains a congestion window (cwnd — its own estimate of what the network can handle) alongside the receive window and uses the smaller of the two. The phases:
- Slow start — exponential growth (doubling per RTT, round-trip time) until a threshold or the first loss. Despite the name, it's the fastest phase.
- Congestion avoidance — linear, careful growth (~1 MSS per RTT).
- Loss response — triple duplicate ACKs trigger fast retransmit and halve the window; a full timeout collapses it to one segment and restarts slow start.
Modern variants (CUBIC, BBR) differ in how they probe for capacity, but the invariant holds: one loss event collapses throughput for at least one RTT.
Windowing: why fast + far = tricky
The window math: Max throughput ≈ receive window ÷ RTT. At 100 ms RTT, a classic 64 KB window caps you at ~5 Mbps — on a 1 Gbps pipe. Window scaling (RFC 7323, shift count up to 14) extends windows toward 1 GB.
Why distance eats throughput:
Throughput is window ÷ RTT. A bigger pipe doesn't help if the window can't cover the round trip. Plug your own numbers into the bandwidth-delay product calculator.
MSS (max segment size) is negotiated per direction from the path's MTU (maximum transmission unit — the biggest packet a link can carry): typically 1500 − 20 (IP) − 20 (TCP) = 1460 bytes. Where MTU drops mid-path and ICMP is filtered (the dreaded PMTU black hole), connections hang instead of fragmenting — the fix is MSS clamping on the router doing encapsulation.
The flag vocabulary
Flags are single-bit on/off signals in the TCP header — the envelope's checkboxes:
| Flag | What it signals | What it looks like broken |
|---|---|---|
| SYN / ACK / FIN | Open, acknowledge, close | SYN without SYN/ACK: the service is down or filtered, not the network |
| RST | "This connection does not exist" — abrupt abort | Sprays during troubleshooting point at firewalls killing sessions |
| PSH | "Deliver this to the app now" (normal on interactive/app data) | — |
| ECE / CWR | ECN (explicit congestion notification) signaling — "I felt congestion" without dropping | Blocked by old firewalls that strip the bits |
Read it yourself: a SYN packet, byte by byte
This is the actual TCP header of the SYN from the handshake animation — 20 bytes, no options. Expand each field to see what it means:
offset 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 0000 cc 75 01 bb 8f 2c 41 d0 00 00 00 00 50 02 fa f0 0010 3d 7a 00 00
Bytes 0–1 · Source port: 0xcc75 = 52341
The client's ephemeral port (a temporary high-numbered port the OS picks per connection, so return traffic can find the right socket).
Bytes 2–3 · Destination port: 0x01bb = 443
The service being contacted — 443 is HTTPS. A SYN to a port with no listener earns a RST (or silence, if filtered).
Bytes 4–7 · Sequence number: 0x8f2c41d0
The client's random ISN (initial sequence number — randomized so old duplicate packets can't be mistaken for new data). Wireshark's "relative sequence numbers" display this as 0.
Bytes 8–11 · Acknowledgment number: 0
Zero and meaningless here — the ACK flag isn't set yet, so there's nothing to acknowledge.
Bytes 12–13 · Data offset + flags: 0x50 0x02
0x50: header length 5 × 4 = 20 bytes, no options. 0x02: only the SYN flag is set. No data payload follows, yet the SYN still consumes one sequence number (that's why the server's SYN/ACK acknowledges 1, not 0).
Bytes 14–15 · Window: 0xfaf0 = 64240
The client's opening receive window: "I can buffer 64,240 bytes." If you see this shrink toward zero mid-transfer, the receiver — not the network — is the bottleneck.
Bytes 16–19 · Checksum + urgent pointer
0x3d7a checksum lets the receiver detect corruption (a mismatch means the segment is discarded, triggering retransmission). 0x0000 urgent pointer: unused unless the URG flag is set.
Tears in the fabric: TIME_WAIT and keepalives
TIME_WAIT (2× MSL, maximum segment lifetime — typically 60 s total) after closing guards against delayed duplicates corrupting the next connection. Keepalives detect a dead peer without ending idle connections.
The five-minute TCP health check
- Is the handshake completing? (SYN ⇒ SYN/ACK ⇒ ACK)
- Are duplicate ACKs/retransmissions spiking? (loss, reordering, or buffer storms)
- Is the window shrinking to zero? (slow receiver or application)
- Is window scaling on, and is the window large enough for this RTT? (run the BDP calculator)
- Are there RSTs? (who sent them, and was it a policy decision?)
- Sequence and ACK numbers are the protocol's memory — learn to read them.
- The receive window is flow control (per connection); congestion control reacts to the network.
- Retransmissions and duplicate ACKs are the signature of congestion or loss.
- Window scaling is required to fill any fast or long pipe.