TCP (Transmission Control Protocol) is one of the most important protocols used in computer networks. It operates at the Transport Layer of the TCP/IP model and provides reliable communication between applications running on different devices.
TCP ensures that data is transmitted correctly, in the proper order, and without duplication. To perform these operations, TCP adds a control header to the data before transmitting it over the network. This control information is known as the TCP header.
The TCP header contains several fields that help identify applications, track transmitted data, manage connections, detect errors, and control the flow of information.
Among these fields, the source port address and destination port address play an important role in identifying the applications involved in communication.
What is TCP Header?
The TCP header is the control part of a TCP segment that carries important information required for reliable communication between sender and receiver in a computer network. It is added at the beginning of each data segment and helps in managing the transmission process. The TCP header contains fields such as source port, destination port, sequence number, acknowledgment number, flags, window size, checksum, and urgent pointer. These fields work together to ensure proper connection establishment, data ordering, error checking, and flow control. Therefore, the TCP header plays a key role in providing accurate and reliable data delivery across networks.

Figure: TCP Header
What is TCP(Transmission Control Protocol)?
TCP (Transmission Control Protocol) is a connection-oriented transport-layer protocol that provides reliable, ordered, byte-stream delivery between applications.
- It operates at the Transport Layer (Layer 4) of the OSI model and is an important part of the TCP/IP protocol suite used for internet communication.
- TCP creates a logical connection between the sender and receiver before starting data transmission.
- It ensures that data is delivered accurately and in the correct order by using sequence numbers and acknowledgements.
- TCP also detects errors using a checksum mechanism and retransmits any lost or corrupted packets to maintain data integrity.
- It includes fields such as port numbers, sequence numbers, acknowledgement numbers, flags, window size, checksum, and urgent pointer, which help in managing connection establishment, data transfer, error detection, and flow control.
Connection Establishment and Termination (TCP)
Connection establishment and termination explain how two devices start and end a reliable communication session in TCP. Since TCP is connection-oriented, it first creates a proper link before sending data and then closes it in a controlled way after communication is complete.
1. Connection Establishment (Three-Way Handshake)
TCP establishes a connection using a process called the Three-Way Handshake. This ensures both sender and receiver are ready for communication.
- SYN (Synchronize): The sender sends a SYN request to start a connection.
- SYN-ACK (Synchronize-Acknowledge): The receiver replies with SYN-ACK to accept the request and confirm readiness.
- ACK (Acknowledge): The sender sends an ACK to confirm the connection is fully established.
This process ensures both sides are synchronized before data transfer begins, which helps in avoiding data loss and errors at the start of communication.

Figure: Three-Way Handshake
2. Connection Termination (Four-Way Handshake)
TCP closes the connection using a Four-Way Handshake to ensure both sides finish communication safely.
- FIN (Finish): The sender sends a FIN signal to request closing the connection.
- ACK (Acknowledge): The receiver acknowledges the FIN request.
- FIN (Finish from Receiver): The receiver also sends a FIN when it is ready to close.
- ACK (Acknowledge): The sender sends the final ACK, completing the termination.
This step-by-step process ensures that all data is properly transmitted before the connection is fully closed, making communication safe and complete.

Figure: Four-Way Handshake
Working of TCP Header
1. Connection Establishment (Three-Way Handshake)
TCP starts communication using a process called the Three-Way Handshake. First, the sender sends a SYN signal to request a connection. Then, the receiver replies with a SYN-ACK signal to confirm readiness. Finally, the sender sends an ACK signal to complete the connection. This process ensures both sender and receiver are synchronized and ready for reliable data transfer before communication begins.
2. Segmentation of Data
In this step, TCP divides large data into smaller parts called segments. Each segment is assigned a unique sequence number for proper identification and tracking. This helps the receiver to arrange data in the correct order during reassembly. As a result, data transmission becomes more efficient and manageable across the network.
3. Data Transmission
After segmentation, TCP sends data segments over the network along with header information. The TCP header contains important details such as source port, destination port, sequence number, and control flags. These details help in proper routing and delivery of data. Therefore, TCP ensures that each segment reaches the correct destination safely.
4. Acknowledgement Mechanism
TCP uses acknowledgements to confirm successful data delivery. When the receiver gets the data correctly, it sends an ACK signal back to the sender. The ACK number indicates the next expected byte of data. This process ensures that no data is lost and communication remains reliable.
5. Error Control and Retransmission
TCP continuously checks for errors using sequence numbers and acknowledgements. If any segment is lost or corrupted during transmission, it is detected easily. Then TCP automatically retransmits the missing or damaged segments. This ensures complete, accurate, and error-free data delivery.
6. Flow Control
Flow control in TCP manages the speed of data transmission between sender and receiver. The receiver uses a window size field to inform the sender how much data it can handle. This prevents data overload at the receiver side. Therefore, smooth and balanced communication is maintained throughout the process.
7. Connection Termination
TCP closes the connection using FIN and ACK flags. Both sender and receiver confirm that all data has been successfully transferred before closing. Once confirmed, the connection is terminated in a proper and organized way. This ensures a clean and graceful end to communication between devices.
Functions of TCP Header
The TCP header performs several important functions that help in reliable communication between sender and receiver. Each function works together to ensure that data is delivered safely, in order, and without errors.
Following are the functions of TCP Header:-
1. Segmentation and Reassembly
TCP divides large messages into smaller segments before sending them over the network. Each segment is carried with a sequence number in the TCP header. At the receiver side, these segments are again arranged in the correct order to rebuild the original message. This ensures smooth and organized data transfer.
2. Reliable Data Delivery
One of the main functions of the TCP header is to ensure reliable communication. It uses acknowledgment (ACK) to confirm that data has been received successfully. If any data is lost, TCP automatically retransmits it. This guarantees complete and error-free delivery.
3. Flow Control
TCP manages the speed of data transmission using the window size field in the header. This prevents the sender from sending too much data at once. As a result, the receiver is not overloaded, and communication remains smooth and stable.
4. Error Detection
The TCP header contains a checksum field that helps detect errors in data during transmission. If any error is found, the segment is discarded or retransmitted. This ensures that only correct data reaches the receiver.
5. Connection Management
TCP handles both connection establishment and termination using control flags like SYN, ACK, and FIN. It ensures that both sender and receiver are ready before data transfer begins. It also ensures a proper closing of the connection after communication ends.
6. Data Ordering
TCP ensures that data segments are delivered in the correct sequence using sequence numbers. Even if packets arrive out of order, they are rearranged properly at the receiver side. This maintains data consistency and accuracy.
7. Multiplexing
TCP allows multiple applications to communicate over the same network using port numbers. The source and destination port fields in the header help identify different processes. This enables multiple services like browsing, email, and file transfer to work simultaneously.
What is of UDP Header?
The UDP header is the control section of a UDP datagram used in the User Datagram Protocol to support fast and simple communication in a computer network. It is added at the beginning of each datagram and contains only essential information needed for data transfer. The UDP header includes four main fields: source port, destination port, length, and checksum. These fields help in identifying applications and checking basic errors during transmission. Therefore, the UDP header is lightweight and supports quick data delivery without connection setup.

Figure: UDP Header
Working of UDP
1. No Connection Establishment
UDP does not establish any connection before sending data. There is no handshake process like in TCP, so communication starts immediately. This reduces delay and makes transmission faster. It is useful for real-time applications where quick delivery is important.
2. Data Transmission (Datagrams)
UDP sends data in the form of small packets called datagrams. Each datagram is independent and carries its own header information. These packets travel separately through the network. This independence allows fast transmission but may lead to loss or disorder.
3. No Acknowledgement
UDP does not send acknowledgements after receiving data. The sender does not get confirmation whether the data reached the receiver. This reduces overhead and increases speed. However, it makes communication unreliable.
4. No Error Recovery
UDP does not provide any mechanism to recover lost or corrupted data. It only uses a checksum to detect errors in transmission. If an error is found, the packet is simply discarded. There is no retransmission of lost data.
5. No Flow Control
UDP does not control the rate of data transmission. The sender continues to send data without checking the receiver’s capacity. This can sometimes overload the receiver. However, it helps maintain high speed in communication.
6. No Ordering Guarantee
UDP does not ensure that packets arrive in the correct order. Datagrams may reach the destination in a different sequence. The protocol does not rearrange them. If ordering is needed, it must be handled by the application itself.
Difference Between TCP Header and UDP Header
| Basis | TCP Header | UDP Header |
|---|---|---|
| Header Size | TCP header is large (20 to 60 bytes). | UDP header is small (8 bytes only). |
| Complexity | It is complex with many fields and control options. | It is simple with only basic fields. |
| Connection Type | TCP is connection-oriented and uses handshake. | UDP is connectionless and no handshake is used. |
| Reliability | Provides reliable data transfer with acknowledgment. | No guarantee of data delivery or acknowledgment. |
| Error Control | Strong error detection and correction using checksum and retransmission. | Only basic error checking using checksum, no correction. |
| Flow Control | Supports flow control using window size field. | No flow control mechanism is available. |
| Ordering of Data | Ensures data arrives in correct order using sequence numbers. | No ordering guarantee for data packets. |
| Speed | Slower due to additional processing and control. | Faster due to minimal header and no control overhead. |
| Header Fields | Includes sequence number, acknowledgment number, flags, window size, etc. | Includes only source port, destination port, length, and checksum. |
| Usage | Used in web browsing, emails, file transfer, banking systems. | Used in gaming, video streaming, voice calls, DNS |
TCP and UDP are important transport layer protocols used for communication over computer networks. TCP provides reliable, connection-oriented communication by using features such as acknowledgements, sequence numbers, retransmission, flow control, and error checking. Its header contains important control fields that help maintain secure and organized data transmission between sender and receiver.
On the other hand, UDP provides fast and connectionless communication with minimal overhead. Although UDP does not guarantee reliable delivery or packet ordering, it is suitable for real-time applications such as video streaming, online gaming, and voice communication. Therefore, TCP is preferred where reliability and accuracy are important, while UDP is used where speed and low delay are the main requirements.