Part AThe TCP header
The header layout
A TCP header is 20 bytes before options, and up to 60 with them. It carries everything TCP needs: ports, the two numbers from chapter 17, control flags, the receive window and a checksum. Compare UDP's two rows (chapter 15):
Five fixed rows = 20 bytes. Options add up to 10 more rows. UDP needs 2 rows; everything extra here is what reliability costs.
A real SYN, byte by byte
Here is the first segment of the handshake from chapter 16: the laptop's SYN to kade-api, as it leaves the laptop (before home NAT changes the source). Its checksum was computed for real, including the pseudo-header:
40 bytes: the fixed 20, then 20 bytes of options. There is no data in a SYN. Offset byte a0: the top 4 bits (a = 10) are the data offset. Flags byte 02: only the SYN bit is set. Checksum cc 12 covers a pseudo-header with 192.168.1.23 → 34.87.120.15, protocol 6 (TCP).
Every field
| # | Field | Size | In the SYN | Job |
|---|---|---|---|---|
| 1 | Source port | 16 bits | ce 4e = 52814 | The sending program (a temporary port) |
| 2 | Destination port | 16 bits | 01 bb = 443 | The receiving program (HTTPS) |
| 3 | Sequence number | 32 bits | 9a 7c 41 f2 = 2,591,834,610 | The random ISN (chapter 17) |
| 4 | Acknowledgement number | 32 bits | 00 00 00 00 | Unused: the ACK flag is off in a SYN |
| 5 | Data offset | 4 bits | a = 10 → 10 × 4 = 40 bytes | Header length in 4-byte rows, so the receiver knows where data starts |
| 6 | Flags | 9 bits (+3 reserved) | 002 = SYN only | Section 4 |
| 7 | Window | 16 bits | fa f0 = 64,240 | Receive buffer space: flow control (section 5) |
| 8 | Checksum | 16 bits | cc 12 | Same method as UDP; mandatory for TCP |
| 9 | Urgent pointer | 16 bits | 00 00 | Only used with the URG flag (almost never) |
| 10 | Options | 0-40 bytes | 20 bytes: MSS, SACK, timestamps, window scale | Section 6 |
Control flags
| # | Flag | Meaning | tcpdump shows |
|---|---|---|---|
| 1 | SYN | Start a connection (handshake) | [S]; with ACK: [S.] |
| 2 | ACK | The acknowledgement number is valid. Set on every segment after the first SYN. | . |
| 3 | FIN | Gracefully close this direction | [F.] |
| 4 | RST | Abort the connection right now | [R] |
| 5 | PSH | Push: hand this data to the app now, do not wait for more | [P.] |
| 6 | URG | Urgent data (see the urgent pointer). Legacy, almost unused. | [U] |
| 7 | ECE / CWR | Explicit congestion notification: routers mark packets instead of dropping them | [E] [W] |
Which flags each segment of a normal connection carries:
| # | Segment | SYN | ACK | PSH | FIN | RST |
|---|---|---|---|---|---|---|
| 1 | SYN | ● | ||||
| 2 | SYN-ACK | ● | ● | |||
| 3 | ACK | ● | ||||
| 4 | HTTP request / response | ● | ● | |||
| 5 | FIN | ● | ● | |||
| 6 | Reset (refused, or aborted) | sometimes | ● |
The window: flow control
Every segment carries the sender's receive window: "I have room for N more bytes". The other side must never have more than N unacknowledged bytes in flight. If kade-db is busy and its buffer fills, it advertises a smaller window, down to 0 ("stop"), then a bigger one again when it catches up. This is flow control from chapter 16.
The window also limits speed. At most one window of data can be sent per round trip, so:
max speed ≈ window ÷ round-trip time
| 64 KB window, home → kade-api (41 ms) | 65,535 × 8 bits ÷ 0.041 s ≈ 12.8 Mbit/s, even on a 100 Mbit/s line |
| With window scaling (e.g. 3 MB) | ≈ 600 Mbit/s: now the line is the limit |
Options, agreed in the handshake
| # | Option | Bytes in our SYN | Value | Purpose |
|---|---|---|---|---|
| 1 | MSS | 02 04 05 b4 | 1460 | "Send me at most 1460 bytes of data per segment" (Part B) |
| 2 | SACK permitted | 04 02 | yes | Selective ACKs allowed (chapter 17) |
| 3 | Timestamps | 08 0a … | 10 bytes | Better RTT measurement; protects against wrapped numbers (chapter 17) |
| 4 | No-operation | 01 | - | Padding so the next option lines up |
| 5 | Window scale | 03 03 07 | × 27 = × 128 | Real window = window field × 128 |
Part BHow big can a segment be?
MTU
The MTU (Maximum Transmission Unit) is the largest packet a link can carry in one piece. For classic Ethernet and most WiFi it is 1,500 bytes (chapter 1). Anything bigger must be split before it can cross that link. Different links have different MTUs:
| Home WiFi, office Ethernet | 1,500 |
| kade-vpc (GCP's default) | 1,460 can be set to 1,500 or up to 8,896 |
| A VPN tunnel (office → cloud, later) | less, e.g. 1,400: the tunnel adds its own headers |
| Some home fibre / DSL links (PPPoE) | 1,492 |
MSS
The MSS (Maximum Segment Size) is the largest amount of application data one TCP segment can carry. It is the MTU minus the IP and TCP headers:
1,500 MTU − 20 IP − 20 TCP = 1,460 MSS
- Each side announces its MSS in the SYN (section 6), based on its own link. Each then sends segments no bigger than what the other side announced.
- Options eat into it. With the timestamp option on every segment (12 bytes with padding), each full segment really carries 1,448 bytes of data.
- Inside GCP, MTU 1,460 gives MSS 1,420, so kade-api and kade-db use smaller segments than your laptop.
TCP uses the MSS to slice your byte stream. When kade-api sends a 4,000-byte order list to your laptop:
Try other links, tunnels and sizes:
- Usable MTU inside the tunnel
- 1,500 − 0 = 1,500
- MSS announced
- 1,500 − 20 (IP) − 20 (TCP) = 1,460
- Data per full segment
- 1,460 − 12 (options) = 1,448
- Segments needed
- 4,000 ÷ 1,448 → 3
- Bytes in IP packets
- 4,156 (headers are 3.8%)
Fragmentation
If an IP packet is still too big for a link's MTU, the IP layer can fragment it: split it into smaller IP packets, which are put back together only at the final destination. The IP header has fields just for this:
| Identification | The same number on every fragment of one packet, so they can be matched |
| DF flag (Don't Fragment) | "Do not split me" (section 10) |
| MF flag (More Fragments) | 1 on every fragment except the last |
| Fragment offset | Where this piece's data starts, counted in 8-byte units |
A 1,500-byte packet (1,480 bytes after its IP header) without DF reaches the 1,400-byte VPN link:
before: one packet, 1,500 bytes
Fragmentation works, but it is avoided:
- Lose one fragment, lose the whole packet. TCP must resend the entire segment.
- Extra work for routers and for the receiver, which must hold fragments until all arrive.
- Firewalls and NAT struggle: only the first fragment contains the TCP/UDP ports.
- IPv6 routers never fragment at all. Only the sender may.
DF and path MTU discovery
To avoid fragmentation, hosts use PMTUD (Path MTU Discovery), which chapter 13 introduced from the ICMP side. TCP sends every packet with the DF bit set. A router that cannot forward it without splitting must drop it and send back ICMP type 3, code 4 ("fragmentation needed", with the next link's MTU). The sender lowers its segment size for that destination:
Why tcpdump shows giant segments: NIC offloads
Capture on your own laptop or on kade-api and you may see TCP segments of 30,000 or 64,000 bytes, far above the 1,460 MSS, and "bad checksum" warnings on packets you sent. Nothing is broken. Modern network cards take over some of TCP's work, and tcpdump watches from a point before the card does it:
| # | Offload | Direction | What happens | What tcpdump shows |
|---|---|---|---|---|
| 1 | TSO / GSO (segmentation offload) | sending | The OS hands the card one big chunk (up to 64 KB). The card cuts it into MSS-sized segments and copies the headers onto each. | One huge "segment", e.g. length 65160 |
| 2 | GRO / LRO (receive offload) | receiving | The card or driver merges many arriving segments of one connection into one big one before the OS sees them. | Big segments arriving too |
| 3 | Checksum offload | sending | The card fills in the TCP/UDP checksum just before sending (chapter 15). | incorrect or bad checksum on outgoing packets only |
what the OS gives the card, and what tcpdump sees
To see the real on-the-wire segments, capture on another machine, a switch mirror port, or (for a quick test only) turn the offloads off with ethtool. Cloud VMs use the same tricks on their virtual network cards.
Summary
| # | Idea | In one line | New terms |
|---|---|---|---|
| 1 | Header | 20 bytes + up to 40 of options; data offset says where data starts | data offset |
| 4 | Flags | SYN, ACK, FIN, RST, PSH, URG (+ ECE, CWR) | control flags |
| 5 | Window | Flow control; speed ≤ window ÷ RTT | receive window, window scaling |
| 6 | Options | MSS, SACK, timestamps, window scale: set in the handshake | |
| 7 | MTU | Largest packet per link; the path MTU is the smallest on the path | path MTU |
| 8 | MSS | MTU − IP − TCP = 1,460; announced in the SYN | MSS |
| 9 | Fragmentation | IP splits too-big packets; fragile, avoided | fragment, MF, offset |
| 10 | PMTUD | DF + ICMP 3/4 finds the right size; blocked ICMP = stalls | DF, PMTUD, MSS clamping |
| 11 | Offloads | The card cuts, merges and checksums; tcpdump sees the "before" view | TSO, GSO, GRO, checksum offload |
Try it yourself
SYNs with their options
- Steps:
sudo tcpdump -n -v -i en0 'tcp[tcpflags] & tcp-syn != 0', then open any site - What to look for:
options [mss 1460,sackOK,TS …,nop,wscale 7] - From section: 6. Options, agreed in the handshake
sudo tcpdump -n -v -i en0 'tcp[tcpflags] & tcp-syn != 0'Your interface's MTU
- What to look for:
mtu 1500. - Runs on: macOS · Linux: ip link show
- From section: 7. MTU
ifconfig en0 | grep mtuThe path MTU, hop by hop
- What to look for:
pmtu 1500, or a smaller value where it drops. - Runs on: Linux
- From section: 10. DF and path MTU discovery
tracepath api.kade.lkDF set, largest size that fits 1,500
- What to look for: 1,473 fails with "message too long" / "frag needed".
- Runs on: macOS · Linux: ping -M do -s 1472
- From section: 10. DF and path MTU discovery
ping -D -s 1472 1.1.1.1Per-connection MSS and path MTU
- What to look for:
mss:1448(timestamps on),pmtu:1500. - Runs on: Linux
- From section: 8. MSS
ss -tiWhich offloads are on
- What to look for:
tcp-segmentation-offload: on,generic-receive-offload: on. - Runs on: Linux, e.g. on kade-api (interface may be ens4)
- From section: 11. Why tcpdump shows giant segments: NIC offloads
ethtool -k eth0 | grep -E 'segmentation|receive-offload|checksum'The VPC's MTU
- What to look for:
1460unless changed. - From section: 7. MTU
gcloud compute networks describe kade-vpc --format='value(mtu)'