TCP Header and Its Fields
Introduction
TCP (Transmission Control Protocol) is a connection-oriented, reliable protocol in the Transport Layer of the
OSI and TCP/IP models. It ensures error-free, in-order delivery of data between systems. Each TCP segment
contains a TCP header which carries crucial information for managing TCP communication.
TCP Header Format Diagram
0 4 8 12 16 20 24 28 32 bits
-----------------------------------------------------------------------------------------------
| Source Port | Destination Port | Sequence Number |
|---------------------------------------------------------------------------------------------|
| Acknowledgment Number (if ACK flag is set) |
|---------------------------------------------------------------------------------------------|
| Data |Rese-| Control Flags | Window Size |
|Offset |rved |URG|ACK|PSH|RST|SYN|FIN| |
|---------------------------------------------------------------------------------------------|
| Checksum | Urgent Pointer (if URG flag is set) |
|---------------------------------------------------------------------------------------------|
| Options and Padding (if any) |
|---------------------------------------------------------------------------------------------|
Explanation of Each TCP Header Field
Source Port (16 bits):
Identifies the port number of the sender application (e.g., port 80 for HTTP).
Destination Port (16 bits):
Identifies the receiver application's port number.
Sequence Number (32 bits):
Used for data ordering. It specifies the number of the first byte of data in the segment.
Acknowledgment Number (32 bits):
Specifies the next byte expected by the receiver, enabling reliable delivery.
TCP Header and Its Fields
Data Offset (4 bits):
Indicates the size of the TCP header (in 32-bit words). Minimum is 5 (i.e., 20 bytes).
Reserved (3 bits):
Reserved for future use; must be set to 0.
Control Flags (6 bits):
URG: Urgent pointer valid | ACK: Acknowledgment valid | PSH: Push data
RST: Reset connection | SYN: Synchronize sequence | FIN: Finish connection
Window Size (16 bits):
Specifies the number of bytes the sender is willing to receive (flow control).
Checksum (16 bits):
Used for error checking on the TCP header and data.
Urgent Pointer (16 bits):
Valid only if URG flag is set. Points to the last urgent byte in the segment.
Options (Variable length):
Used for additional features (e.g., MSS, Window Scaling, Timestamps).
Padding (Variable):
Ensures that the TCP header ends on a 32-bit boundary.
Conclusion
The TCP header plays a vital role in ensuring reliable communication between sender and receiver. Its
well-structured fields support sequencing, flow control, error detection, and proper connection
establishment/termination - forming the backbone of TCP's reliable data transfer.