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.
Why is the TCP Header Important?
The TCP header works like a set of rules for sending data online. It’s a tiny part of each data packet, but nothing would work right without it. The header makes sure your data arrives safely and correctly.
The TCP header is important for several reasons. Some of which are:
It Directs Traffic to the Right Program
Every header has port numbers. These numbers tell the computer which program needs the data. Your email goes to your email program. Web pages go to your browser. The port numbers keep everything separate and organized.
It Puts Data in the Correct Order
Big files get split into small chunks before sending. Each chunk gets its own number, i.e., sequence number. The computer that receives them uses these numbers to put the chunks back in order. You get the whole file, not mixed-up pieces.
It Confirms Data Was Received.
The header uses an acknowledgment number. This is a number that indicates to the sender that data was received properly. When acknowledgment is not received, the sender knows that a packet was lost. It then resends the missing piece. This process guarantees data delivery.
It Manages the Connection
Special bits, or flags, in the header control the conversation between two devices. Flags are used to start a connection, end it, and reset it if a problem occurs. These flags act as the signals that manage the entire data transfer process from start to finish.
It Prevents Data Overload
The header tells the sender how much data to send at once. The receiver sets this limit based on what it can handle. This keeps data flowing smoothly.
It Checks for Errors
A checksum value is included in the header. Both computers do the same math on the data. If their answers match, the data is good. If the results do not match, it means the data was corrupted during transit. The packet is then discarded. The checksum acts as quality control.
TCP Header Format and Its Components
The TCP header Format comprises of different components. Each component serves a different purpose and ensures data integrity through checksums, maintains message ordering via sequence numbers, and guarantees delivery completeness using acknowledgment-based protocols. Let us first look at the TCP header format.
In the above image, we have shown the TCP header format.
Components of TCP Header
Below, we have explained different components of TCP header.
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 3-bit field that is reserved for future use.
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.
These are all the components of TCP Header.
How to View and Analyze the TCP Header?
As a network engineer, you need to look at TCP headers. This helps you fix problems, make the network faster, or simply learn. You need the right tools for the job. Fortunately, several great, free tools can help.
Wireshark
Wireshark is your go-to tool for a deep look. It is a powerful network analyzer that gives you a full, graphical view of your network traffic.
You use it to capture live data from your network. You can also open saved capture files. Wireshark shows you a list of all data packets. When you click on a TCP packet, it breaks down the header for you. Every field is clearly labeled and explained. This is the best way to see every detail, from sequence numbers to window sizes.
Wireshark does more than just show headers. It can create graphs to show you the network speed. You can see how long it takes for data to make a round trip. It also highlights problems like retransmissions, which happen when data gets lost. This visual feedback is key for serious troubleshooting.
tcpdump
Think of tcpdump as a fast, sharp tool for your command line. It is not for casual browsing of traffic. It is for targeted strikes.
You use tcpdump when you know what you’re looking for. You can tell it to show you only the traffic from a specific IP address. Or you can watch only the packets using a certain port.
This makes it perfect for quick checks on a live server. You don’t need a full graphical interface. You just get the raw data you asked for, right away. You can also save the output to a file and open it in Wireshark later for a deeper look.
Nmap
Nmap is different. It’s a network detective. You don’t use it to watch traffic flow. Instead, you use it to test devices on your network.
Nmap sends out special packets and analyzes the replies. The way a device replies to these packets can tell you a lot about it. From the TCP responses, you can find out what ports are open on a server. You can often guess the device’s operating system. You can see what services are running.
For a network engineer, Nmap is essential for security audits and network mapping. It helps you understand what your devices are showing to the outside world.
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
TCP header is an essential part of a TCP segment. It holds key information for the TCP connection and the data. It ensures your information gets to the right place, safe and sound.
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.