Computer Networks · TCP
TCP Header Format and Field Sizes
Overview
Every TCP segment consists of a TCP header followed by data, just as an IP packet has an IP header plus data. The header is a fixed-layout structure whose fields have defined sizes, giving a minimum length of 20 bytes and a maximum of 60 bytes.
Key concepts
- TCP header layout: a fixed sequence of fields, each with a defined size in bits, except the Options field, which is measured in bytes.
- Source Port: 16-bit field identifying the sending port.
- Destination Port: 16-bit field identifying the receiving port.
- Sequence Number: 32-bit field.
- Acknowledgement Number: 32-bit field — distinct from the 1-bit ACK flag.
- Header Length: 4-bit field.
- Reserved: 6-bit field, not used and normally all zeros.
- Flags: six flags of 1 bit each — URG (Urgent), ACK (Acknowledgement), PSH (Push), RST (Reset), SYN (Synchronization), FIN (Finish).
- Advertisement Window / Window Size: 16-bit field used for flow control.
- Checksum: 16-bit field.
- Urgent Pointer: 16-bit field.
- Options: 0 to 40 bytes — the only field measured in bytes.
How it works
The header fields appear in this order, with sizes in bits unless stated otherwise:
- Source Port — 16 bits
- Destination Port — 16 bits
- Sequence Number — 32 bits
- Acknowledgement Number — 32 bits
- Header Length — 4 bits
- Reserved — 6 bits
- Flags — 1 bit each: URG, ACK, PSH, RST, SYN, FIN
- Advertisement Window / Window Size — 16 bits
- Checksum — 16 bits
- Urgent Pointer — 16 bits
- Options — 0 to 40 bytes
Formulas
-
Fixed header size in bits
-
Options size
-
Minimum TCP header length
-
Maximum TCP header length
-
TCP Header Field Layout
Drawing the diagram…
- Shows the fixed order of TCP header fields with their sizes, from Source Port through the optional Options field.
Worked examples
Computing minimum and maximum header length:
- Each row of the header diagram is 32 bits = 4 bytes.
- The first 5 rows are always present: bytes, so the minimum header length is 20 bytes.
- If Options are used, they can be at most 40 bytes.
- Maximum header length bytes.
Comparison
| Field | Size | Unit |
|---|---|---|
| Source Port | 16 | bits |
| Destination Port | 16 | bits |
| Sequence Number | 32 | bits |
| Acknowledgement Number | 32 | bits |
| Header Length | 4 | bits |
| Reserved | 6 | bits |
| URG, ACK, PSH, RST, SYN, FIN | 1 each | bit |
| Window Size | 16 | bits |
| Checksum | 16 | bits |
| Urgent Pointer | 16 | bits |
| Options | 0 to 40 | bytes |
Revision summary
- TCP header = fixed 20-byte base + optional Options field (0–40 bytes).
- Minimum header size is 20 bytes; maximum header size is 60 bytes.
- All fields are specified in bits except Options, which is in bytes.
- Each of the six flags (URG, ACK, PSH, RST, SYN, FIN) is exactly 1 bit.
- Do not confuse the Acknowledgement Number (32-bit field) with the ACK flag (1-bit field), or the Sequence Number (32-bit field) with the SYN flag (1-bit field).
- The Window Size field is used for flow control.
- Reserved bits are unused and are normally zero.
Previous-year exam insights
- The 4-bit Header Length / Data Offset field gives the TCP header length in 32-bit words, so actual header bytes = field value × 4;
legal values are 5 through 15, corresponding to 20 through 60 bytes. - TCP does not include IPv4 header fields such as source/destination IP address, fragment offset, total length, TTL, or protocol; those belong to the IP header.
Asked inUGC NET 2014 - The TCP checksum is computed over a pseudo-header containing source IP, destination IP, zero, protocol, and TCP length, plus the TCP header and data.
- TCP options are padded with zero bytes to a 32-bit boundary, and the 40-byte maximum for Options includes padding.
- The Acknowledgement Number is valid only when the ACK flag is set and gives the next byte expected; the Sequence Number gives the first data byte, with SYN and FIN each consuming one sequence number.
- The 16-bit Window Size allows at most 65535 bytes per window without scaling; the Window Scale option can increase the effective window.