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
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
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.
Note: The initial sequence number is a randomly generated number between and .
Acknowledgement 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 and its data field had bytes of data, the sequence number of the next expected segment or the acknowledgment number would be . This helps TCP to identify if a segment was missing or out of order.
Header Length
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 or 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 would represent . 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
The header has a 4-bit field that is reserved and is always set to . 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!
Given an initial sequence number of and bytes sent in a TCP segment, what will be the value of the sequence number field in the next TCP packet header?
The sequence number of the last byte in the previous segment i.e.,
The number of bytes in the first segment, i.e.,
The sequence number of the next expected byte to be sent i.e.,
The sequence number of the next expected byte to be sent i.e.,
We’ll continue dissecting the TCP headers in the next lesson!
Get hands-on with 1400+ tech skills courses.