TCP segment structure

TCP Header

Sequence number

It represents the offset of the first byte of the segment in relation to the first segment. It’s used to keep track of all segments (and retransmit if required).

Acknowledgement number

If the ACK flag is set (see below), the acknowledgement number contains the sequence number of the  next segment it expects. This is a type of forward acknowledgement .

Data offset (header length)

This specifies the number of rows in the header. In other words, this lets you know where the header ends and actual data (TCP payload) begins.

TCP Flags

URG: set if the Urgent Pointer is used.

ACK: set if the Acknowledgement number is valid and should be considered.

PSH: set to push the data as it comes without waiting for the buffer to get full.

RST: used to forcefully reset a connection that can’t continue due to unexpected reasons.

SYN: used to initiate a connection.

FIN: ┬áthis is set when there is no more data to send. It’s used to end cleanly a connection.

Window size

It is a 16 bit field and it notifies to the sender the quantity of data the receiver will accept without sending a confirmation. TCP window demonstration.

Urgent pointer

This relies (is validated by) on the URG flag above and it contains the sequence number of the first non-urgent segment after the urgent data has been sent.