Christmas Offer - Every Learner Must Check Out - Flat 88% OFF on All Access Pass
00
days
:
00
hours
:
00
minutes
:
00
seconds
PyNet Labs- Network Automation Specialists

TCP Header

Author : PyNet Labs
Last Modified: January 6, 2024 
A blog featured image with text Transmission Control Protocol - TCP Header and a server image.

Introduction

TCP, or Transmission control protocol, is a widely used protocol on the Internet that is reliable and connection oriented. TCP operates at the transport layer of the OSI model and ensures the correct ordered delivery of data packets from sender to receiver in a network. TCP is used by many applications that are totally dependent on reliable and secure communication.

In this blog, we will explain the TCP header, which is one of the parts of the TCP segment and contains information regarding the TCP connection and the data being transmitted. We will discuss the structure, format, and meaning of each field in the TCP header.

CCNA Training makes you familiar with Transmission Control Protocol. However, TCP Header is an advanced topic which is covered in advanced training, such as ENCOR 350-401 and CCNP ENARSI. Let’s start by understanding what a TCP header really is.

What is TCP Header?

A TCP header size can be a minimum of 20-byte and a maximum of 60-byte segments of data that come before the data in a TCP segment. It consists of 10 fields and an optional field that specifies parameters and flags for the TCP connection. The TCP header helps keep track of the communication state between two TCP endpoints, which are identified by their IP addresses and port numbers.

TCP header plays a vital role in flow control, error control, congestion control, and security. Flow control ensures that the receiver is not overcrowded with data at once that it can handle from the sender. When we talk about error control, it rectifies any errors or losses during transmission. Congestion control prevents network congestion by adjusting the sending rate based on network conditions. Lastly, security measures guarantee that unauthorized parties cannot tamper with or intercept the data.

Components of TCP header

Below, we have shown the format of a TCP header and explained each field in detail.

TCP Header format divided into various bits such as source port, destination port, sequence, acknowledgement number, etc.

Source Port Number

The source port number field is 16-bit, which specifies the port number of the application that is sending the data. Let’s take a case where a browser sends a request to a web server. Now, the browser randomly decides the source port and the destination port will be 80, as it is the standard port for HTTP. There are other ports also, such as port 25 for SMTP, port 22 for SSH, etc.

Destination Port Number

This field is 16-bit, the same as the source port number field. The only difference is that it specifies the port number for the application that is receiving the data. For example, when a browser sends a response, the source port will be 80, and the destination port will be the same random number, i.e., the port decided by the browser.

Sequence Number

This field is 32-bit that specifies the amount of data that is sent during the TCP session. The main purpose of sequence numbers is to identify each byte of data as well as ensure that the data that has been delivered is in order and without duplication.

Whenever a new TCP connection is established via a three-way handshake, the initial sequence number is set to a random 32-bit bit value. For each byte of data sent, the sequence number is increased by one. The receiver end makes use of this sequence number to acknowledge the data and also assist in making a request for the next segment.

Acknowledgment Number

This field is 32-bit and is mainly used by the receiver in order to acknowledge the data that has been received and also to request the next segment. When we talk about the acknowledgment number, it is equal to the sequence number of the last byte received plus one.

Let’s take an example for better understanding.

In a case where a sender sends a segment with sequence number 1000 and 100 bytes of data, the receiver, in return, sends an acknowledgment with acknowledgment number 1100. It simply means that it has received all bytes up to 1099 and expects byte 1100 next.

Data Offset

This field is 4-bit, which assists in determining the size of the TCP header. The value of this field ranges from 20 bytes to 60 bytes. The data offset field is sometimes also known as the header length field.

Reserved

This is a 6-bit field that is reserved for future use and must be set to zero.

Flags

This field is 9-bit and contains various control bits indicating different states or actions for the TCP connection. Some of the flags are discussed below.

  • URG (Urgent Pointer): Whenever this bit is set, it simply indicates that there is an urgent demand for a particular set of data segments that must be processed before any other data. The urgent pointer field indicates where the urgent data ends.
  • ACK (Acknowledgment): When this bit is set, it shows that the acknowledgment number field is valid and also contains an acknowledgment for the received data.
  • PSH (Push Function): When the push flag is enabled, it means that the data should be delivered to the application by the sender without waiting for more data to fill up the segment.
  • RST (Reset): It simply means resetting the connection. If it is set to 1, the connection will be reset.
  • SYN (Synchronize Sequence Numbers): Enabling this bit simply indicates that the segment is used to initiate a connection establishment. It is used in the three-way handshake process.
  • FIN (Finish): When this bit is set, it means that this segment terminates a connection or confirms the termination of a connection. It is used to close a connection after all data has been exchanged.

Window Size

This field is 16-bit, indicating how many bytes of data can be willingly accepted by the receiver at a given point in time. Sometimes, it is also known as the flow control window. It is important to note that the sender must not send data that is more than the window size as advertised by the receiver. The window size can vary as it depends on network conditions and the receiver’s buffer availability.

Checksum

This field is 16-bit that holds the checksum value which is further utilized in order to verify the integrity of the TCP header and data. The checksum is calculated by adding all 16-bit words in the TCP segment, including the pseudo-header, which contains some fields from the IP header. If, somehow, the value of the checksum is incorrect, the segment is discarded by the receiver.

Urgent Pointer

This field is 16-bit and is mainly used when the URG flag is set. The work of the urgent pointer is to specify how many bytes of data from the current segment are urgent and should give priority while processing before any other data. The urgent pointer is relative to the sequence number. It indicates the sequence number of the last byte of urgent data.

Options

The option field can be up to 40 bytes long. It is used to provide additional features or parameters for the TCP connection, such as MSS (maximum segment size), window scaling, timestamp, etc.

Below, we have shown different fields in the image with real life example.

A real life example of a TCP Header where it shows the various field of TCP Header.

These are all the components of TCP Header.

Frequently Asked Questions

Q1. What is a TCP header?

A TCP header is part of a TCP segment that contains information regarding source and destination ports, sequence and acknowledgement numbers, flags, and options.

Q2. What is meant by header of TCP and UDP?

The header of the TCP and UDP is the part of the data packet. This field contains information such as destination ports, sequence numbers, checksums, and flags. Furthermore, the header assists in identifying, organizing, and verifying the data transmission.

Q3. What is the next header in TCP?

The next header field is used to identify the next header in the packet. It can be an upper-layer protocol or an extension header such as a routing header.

Q4. Which flag in the TCP header is used?

The TCP header has a flag field that consists of six bits. Some of the most common flags are URG, Ack, PSH, RST, SYN, and FIN.

Conclusion

In this blog, we have explained the TCP header in detail. It is an essential part of a TCP segment that holds information regarding the TCP connection as well as the data that is being transmitted. We have seen the structure (including TCP header size), TCP header format, and role of each field in the TCP header, as well as how they are used to establish, maintain, and terminate a TCP connection.

Recent Blog Post

Leave a Reply

Your email address will not be published. Required fields are marked *

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram