Packet Path/

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.

TCP/IP · Intermediate · 14 min · September 30, 2026

Illustration of the TCP three-way handshake between two computers
In plain EnglishTCP is the internet's certified-mail service: every chunk of data gets a return receipt, and anything lost in transit gets re-sent. This article shows how those receipts work (sequence and acknowledgment numbers), how your computer avoids overwhelming the other end (the receive window), and how it avoids overwhelming the network itself (congestion control) — the three mechanisms behind nearly every "the transfer is slow" mystery.

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:

The three-way handshake, animated Client 192.0.2.10:52341 Server 203.0.113.7:443 1. SYN 2. SYN/ACK 3. ACK SYN · seq 0 SYN/ACK · seq 0, ack 1 ACK · ack 1 Relative sequence numbers, Wireshark style. The full cycle repeats every 12 seconds.
The three-way handshake: the client offers a starting sequence number (SYN), the server accepts it and offers its own (SYN/ACK), and the client confirms (ACK). If any of these three packets is missing in a capture, the connection never started.

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:

The sliding window, animated receive window (dashed) 1 2 3 4 5 6 7 8 receiver busy — window shrinks sent, awaiting ACK (in flight) acknowledged
The sender may only keep as many unacknowledged segments inside the dashed window as the receiver advertised. A zero window in a capture means "the receiver is the bottleneck," not the network.

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:

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:

Why distance eats throughput Your laptop client Internet RTT 85 ms · loss 0.4% Web server server data → ← ACKs Every ACK takes 85 ms to return, so the window must hold 85 ms worth of data.
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.

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:

FlagWhat it signalsWhat it looks like broken
SYN / ACK / FINOpen, acknowledge, closeSYN without SYN/ACK: the service is down or filtered, not the network
RST"This connection does not exist" — abrupt abortSprays during troubleshooting point at firewalls killing sessions
PSH"Deliver this to the app now" (normal on interactive/app data)—
ECE / CWRECN (explicit congestion notification) signaling — "I felt congestion" without droppingBlocked 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:

Packet 1 0.000000  192.0.2.10 → 203.0.113.7  TCP  74  52341 → 443 [SYN] Seq=0
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

  1. Is the handshake completing? (SYN ⇒ SYN/ACK ⇒ ACK)
  2. Are duplicate ACKs/retransmissions spiking? (loss, reordering, or buffer storms)
  3. Is the window shrinking to zero? (slow receiver or application)
  4. Is window scaling on, and is the window large enough for this RTT? (run the BDP calculator)
  5. Are there RSTs? (who sent them, and was it a policy decision?)
Try it yourselfRun your own numbers: the bandwidth-delay product calculator shows exactly how window size and RTT cap your throughput — the math behind every "fast pipe, slow transfer" mystery.
Key takeaways
  • 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.