TCP Segment Header

We'll now study TCP headers. They're far more complex than UDP headers and really are what allow for TCP to work properly!

Introduction#

TCP headers play a crucial role in the implementation of the protocol. In fact, TCP segments without actual data and with headers are completely valid. They’re actually used quite often!

The size of the headers range from 20 - 60 bytes. Let’s discuss the header field by field.

Source and Destination Ports#

svg viewer
The source and destination ports are the first fields of the TCP header.

The source and destination port numbers are self-explanatory. They are exactly like the source and destination ports in UDP. Just for a refresher though, the source port is the port of the socket of the application that is sending the segment and the destination port is the port of the socket of the receiving application. The size of each field is two bytes.

Sequence Number#

svg viewer
The sequence number is the second field of the TCP header. It represents the first byte of data in the TCP segment.

Every byte of the TCP segment’s data is labeled with a number called a sequence number. The sequence number field in the header has the sequence number of the first byte of data in the segment.

Each byte of a TCP segment is labeled with a sequence number.

📝 Note The initial sequence number is a randomly generated number between 00 and 23212^{32}-1.

Acknowledgement Number#

svg viewer
The third field in the TCP header is the acknlowledgement number

The acknowledgment number is a 4-byte field that represents the sequence number of the next expected segment that the sender will send or the receiver will receive.

Example#

So if a segment’s sequence number was 4284942849 and its data field had 5959 bytes of data, the sequence number of the next expected segment or the acknowledgment number would be 4290842908. This helps TCP to identify if a segment was missing or out of order.

Header Length#

svg viewer

The length of the TCP header is specified here. This helps the receiving end to identify where the header ends and the data starts from.

📝 Note The header length is represented by 4 bits, i.e., the numbers 000011110000\to1111 or 0150\to15 in decimal which is not enough to represent the potential 60 bytes of the header. Hence, this number is multiplied by 4 upon receiving. So 11111111 would represent 6060. In other words, the way the 4-bit header length field is used to represent a maximum header length of 60, is that this field represents the number of 4-byte words in the header

Reserved Field#

svg viewer
The reserved bits serve as an offset and are left for potential future use

The header has a 4-bit field that is reserved and is always set to 00. This field aligns the total header size to be in multiples of 4 (as we saw was necessary for the header length to be processed).

Quick Quiz!#

1

Given an initial sequence number of 255255 and 5050 bytes sent in a TCP segment, what will be the value of the sequence number field in the next TCP packet header?

A)

The sequence number of the last byte in the previous segment i.e., 254254

B)

The number of bytes in the first segment, i.e., 5050

C)

The sequence number of the next expected byte to be sent i.e., 255255

D)

The sequence number of the next expected byte to be sent i.e., 305305

Question 1 of 40 attempted

We’ll continue dissecting the TCP headers in the next lesson!

Key Features of the Transmission Control Protocol
TCP Header Flags
Mark as Completed
Report an Issue