wire / wire-format / tcp-header

TCP header

The TCP segment header is at least 20 bytes: source and destination ports, a 32-bit sequence number, a 32-bit acknowledgement number, a data-offset/flags word (including SYN/ACK/FIN/RST/PSH/URG), a 16-bit window, checksum, and urgent pointer, followed by optional options padded to a 32-bit boundary.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: TCP segment header · Transmission Control Protocol header

wire format

spec: RFC 9293

Fixed 20-byte header (plus options). Reliable, ordered, connection-oriented transport. The 4-bit Data Offset gives the header length in 32-bit words so a parser knows where options end and payload begins.

fieldsizemeaning
Source Port16 bitsSending port.
Destination Port16 bitsReceiving port.
Sequence Number32 bitsByte-stream sequence number of the first data octet (or the ISN+1 if SYN set).
Acknowledgement Number32 bitsNext sequence number the sender expects, valid when the ACK flag is set.
Data Offset4 bitsHeader length in 32-bit words (5 = 20 bytes minimum, up to 15 = 60 bytes with options).
Reserved4 bitsMust be zero (formerly part of a 6-bit reserved + flags layout).
Flags8 bitsCWR, ECE, URG, ACK, PSH, RST, SYN, FIN control bits.
Window16 bitsReceive window: bytes the sender of this segment is willing to accept (scaled by the Window Scale option if negotiated).
Checksum16 bitsOnes-complement checksum over the header, payload, and a pseudo-header.
Urgent Pointer16 bitsOffset of urgent data, valid when the URG flag is set.
Options0-320 bitsOptional, e.g. MSS, Window Scale, SACK-Permitted, Timestamps; padded with zeros to a 32-bit boundary.

example:

01 BB C0 A8 ... (illustrative ports)

First two bytes 0x01BB = 443 as a destination port (HTTPS). Full segment parsing requires the IP header for length/pseudo-header checksum.

see: wire-format/ipv4-header


provenance

see also

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/tcp-header or /wire-format/tcp-header.json