What are the fields in a TCP header and their purposes?
The TCP header (20 bytes minimum, up to 60 with options) carries source/destination ports, sequence and acknowledgment numbers, header length, reserved bits, control flags, window size, checksum, urgent pointer, and options.
* The fixed 20-byte TCP header, ending with up to 40 bytes of Options. *
TCP Header Structure (20 bytes minimum):
| Field | Size | Purpose |
|---|---|---|
| Source Port | 16 bits | Identifies sending application |
| Destination Port | 16 bits | Identifies receiving application |
| Sequence Number | 32 bits | Tracks segment order |
| Acknowledgment Number | 32 bits | Next expected byte from sender |
| Header Length | 4 bits | Size of TCP header ("data offset") |
| Reserved | 6 bits | Reserved for future use |
| Control Bits | 6 bits | Flags (URG, ACK, PSH, RST, SYN, FIN) |
| Window Size | 16 bits | Number of bytes receiver can accept |
| Checksum | 16 bits | Error checking |
| Urgent Pointer | 16 bits | When the URG flag is set, points to the end of the urgent data within the segment |
| Options | 0-320 bits (0-40 bytes) | Optional settings (e.g., MSS, window scaling, SACK-permitted), padded to a 32-bit boundary |
Watch the name collision: the Urgent Pointer is a 16-bit field that only matters when the separate 1-bit URG control flag is set. Same word, two different things - the flag says "there is urgent data," the pointer says "here is where it ends."
Header length range: the 4-bit Header Length field counts 32-bit words, so it maxes out at 15 × 4 = 60 bytes. Subtract the 20-byte fixed portion and that leaves up to 40 bytes (320 bits) for Options - which is why the simplified slide diagram (showing "0 or 32") understates the real ceiling.
Key insight: TCP is a stateful protocol - it keeps track of the state of the communication session.
Memory tip: TCP header = 20 bytes minimum (think "TCP ≈ Twenty"), expanding to 60 bytes when options are present.
Go deeper:
RFC 9293 §3.1 — Header Format — the authoritative field-by-field definition, including the Data Offset and Urgent Pointer.
TCP segment structure — Wikipedia's annotated header diagram for the carousel.
Maximum segment size — the most common TCP Option carried in those extra bytes.