Chapters

TCP segment, MTU, MSS & fragmentation

This chapter opens the TCP header field by field, then follows the question every sender has to answer: how big can each piece be? That leads to MTU, MSS, fragmentation and path MTU discovery, and to one of the most confusing bugs in networking.

Layers, routing and transport · chapter 18 of 34 · 9 min read

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):

bit →08162431bytes 0-3Source port16Destination port16bytes 4-7Sequence number32 bitsbytes 8-11Acknowledgement number32 bitsbytes 12-15Offset4Res.3Flags9Window16bytes 16-19Checksum16Urgent pointer1620-59Options0 to 40 bytesthenDataup to one MSS

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:

0000cesrc port4e01dst portbb9aseq7c41f200ack000000a0offset02flagsfawindowf0
0016ccchecksum1200urgent0002MSS0405b404SACK ok0208timestamps0ae81b9042
00320000000001NOP03wscale0307

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

#FieldSizeIn the SYNJob
1Source port16 bitsce 4e = 52814The sending program (a temporary port)
2Destination port16 bits01 bb = 443The receiving program (HTTPS)
3Sequence number32 bits9a 7c 41 f2 = 2,591,834,610The random ISN (chapter 17)
4Acknowledgement number32 bits00 00 00 00Unused: the ACK flag is off in a SYN
5Data offset4 bitsa = 10 → 10 × 4 = 40 bytesHeader length in 4-byte rows, so the receiver knows where data starts
6Flags9 bits (+3 reserved)002 = SYN onlySection 4
7Window16 bitsfa f0 = 64,240Receive buffer space: flow control (section 5)
8Checksum16 bitscc 12Same method as UDP; mandatory for TCP
9Urgent pointer16 bits00 00Only used with the URG flag (almost never)
10Options0-40 bytes20 bytes: MSS, SACK, timestamps, window scaleSection 6

Control flags

#FlagMeaningtcpdump shows
1SYNStart a connection (handshake)[S]; with ACK: [S.]
2ACKThe acknowledgement number is valid. Set on every segment after the first SYN..
3FINGracefully close this direction[F.]
4RSTAbort the connection right now[R]
5PSHPush: hand this data to the app now, do not wait for more[P.]
6URGUrgent data (see the urgent pointer). Legacy, almost unused.[U]
7ECE / CWRExplicit congestion notification: routers mark packets instead of dropping them[E] [W]

Which flags each segment of a normal connection carries:

#SegmentSYNACKPSHFINRST
1SYN●
2SYN-ACK●●
3ACK●
4HTTP request / response●●
5FIN●●
6Reset (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
The window field is only 16 bits (max 65,535). The window scale option (section 6) multiplies it, which is how fast long-distance transfers work today.

Options, agreed in the handshake

#OptionBytes in our SYNValuePurpose
1MSS02 04 05 b41460"Send me at most 1460 bytes of data per segment" (Part B)
2SACK permitted04 02yesSelective ACKs allowed (chapter 17)
3Timestamps08 0a …10 bytesBetter RTT measurement; protects against wrapped numbers (chapter 17)
4No-operation01-Padding so the next option lines up
5Window scale03 03 07× 27 = × 128Real window = window field × 128
Most options can only be set in the SYN and SYN-ACK. If one side does not offer an option, it is not used for the whole connection.

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 Ethernet1,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
The path MTU is the smallest MTU of any link on the whole path. That is the real limit.

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:

SEQ 1 · 1,460 bytesSEQ 1461 · 1,460 bytesSEQ 2921 · 1,080
The same split as chapter 1, now with the reason: 1,460 is the MSS your laptop announced (ignoring timestamps to keep the numbers round).

Try other links, tunnels and sizes:

Link MTU
Tunnel
IP version
TCP timestamps
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:

IdentificationThe 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 offsetWhere 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

IPdata · 1,480 bytes
IPdata bytes 0-1375 · 1,376 bytes
IP104
Fragment data must be a multiple of 8 bytes (except the last), so fragment 1 carries 1,376, not 1,380. Each fragment gets its own 20-byte IP header, so the total grows from 1,500 to 1,520.

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:

Office PCkade-db (over VPN)✕1,500-byte packet · DF setdropped at the VPN router: the tunnel carries 1,400ICMP 3/4 from the VPN router · "too big, next MTU 1,400"the PC lowers its packet size for this destination1,400-byte packets · DF setACKeverything flows

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:

#OffloadDirectionWhat happensWhat tcpdump shows
1TSO / GSO (segmentation offload)sendingThe 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
2GRO / LRO (receive offload)receivingThe card or driver merges many arriving segments of one connection into one big one before the OS sees them.Big segments arriving too
3Checksum offloadsendingThe 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

one 64 KB chunk with one set of headers
1448144814481448…14481448
About 45 real segments, each with its own headers and sequence numbers worked out by the card. The saving is CPU: the OS builds headers once per chunk instead of once per segment.

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

#IdeaIn one lineNew terms
1Header20 bytes + up to 40 of options; data offset says where data startsdata offset
4FlagsSYN, ACK, FIN, RST, PSH, URG (+ ECE, CWR)control flags
5WindowFlow control; speed ≤ window ÷ RTTreceive window, window scaling
6OptionsMSS, SACK, timestamps, window scale: set in the handshake
7MTULargest packet per link; the path MTU is the smallest on the pathpath MTU
8MSSMTU − IP − TCP = 1,460; announced in the SYNMSS
9FragmentationIP splits too-big packets; fragile, avoidedfragment, MF, offset
10PMTUDDF + ICMP 3/4 finds the right size; blocked ICMP = stallsDF, PMTUD, MSS clamping
11OffloadsThe card cuts, merges and checksums; tcpdump sees the "before" viewTSO, 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 mtu

The path MTU, hop by hop

tracepath api.kade.lk

DF 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.1

Per-connection MSS and path MTU

  • What to look for: mss:1448 (timestamps on), pmtu:1500.
  • Runs on: Linux
  • From section: 8. MSS
ss -ti

Which offloads are on

ethtool -k eth0 | grep -E 'segmentation|receive-offload|checksum'

The VPC's MTU

  • What to look for: 1460 unless changed.
  • From section: 7. MTU
gcloud compute networks describe kade-vpc --format='value(mtu)'

Spotted a mistake, or something unclear? Suggest an edit on GitHub