TCP flags and sessions cheat sheet

The header, what each flag means, the handshake and the close step by step, and reading flags in a capture.

01 The header (20–60 bytes)

FieldBitsWhat to know
Source / destination port16 + 16Client picks a random high (ephemeral) port; server listens on the well-known one.
Sequence number32Number of the first data byte in this segment. The first one (ISN) is random.
Acknowledgment number32The next byte expected from the other side. Valid only when ACK is set.
Data offset4Header length in 32-bit words: 5 (20 bytes) to 15 (60 bytes).
Reserved4Must be zero. The last of these bits was once the NS flag (see the flags table).
Flags8CWR ECE URG ACK PSH RST SYN FIN.
Window16Receive buffer free, in bytes. The window-scale option multiplies it (up to ×2^14).
Checksum16Covers header, data and a pseudo-header with the IP addresses.
Urgent pointer16Used only with URG.
Options0–320MSS, window scale, SACK and timestamps; most are agreed in the SYN.

On the full sheet

  1. The flags
  2. Opening: the three-way handshake
  3. Closing: graceful and abrupt
  4. Reading flags in a capture
  5. TCP or UDP
  6. Exam traps (5)