askvity

What is TCP Header Format?

Published in Network Protocols 3 mins read

The TCP header is a crucial part of every Transmission Control Protocol (TCP) segment. It's a 20-byte header (minimum) containing essential information for reliable data transmission across a network. While it can grow up to 60 bytes with optional fields, the core consists of ten mandatory fields.

Key TCP Header Fields:

The following fields are critical for TCP's connection-oriented, reliable data transfer:

  • Source Port (16 bits): Identifies the sending application's port number.
  • Destination Port (16 bits): Specifies the receiving application's port number.
  • Sequence Number (32 bits): A unique identifier for each byte sent in the data stream. This allows the receiver to correctly order the received data.
  • Acknowledgement Number (32 bits): Indicates the next expected byte sequence number from the sender. Used for acknowledgement and flow control.
  • Data Offset (4 bits): Specifies the length of the TCP header in 32-bit words. Helps determine the start of the data payload.
  • Reserved (6 bits): Currently unused.
  • Flags (6 bits): Control bits that indicate various aspects of the connection (e.g., SYN, ACK, FIN, RST, PSH, URG). These flags manage connection establishment, data transfer, and termination.
  • Window Size (16 bits): Specifies the receiver's buffer space available for incoming data. It's a crucial element of flow control, preventing the sender from overwhelming the receiver.
  • Checksum (16 bits): An error-detection mechanism to ensure data integrity. The sender calculates the checksum, and the receiver verifies it upon receipt.
  • Urgent Pointer (16 bits): Points to the end of urgent data. Used for out-of-band data transmission, although not frequently used in practice.

TCP Header Size and Options:

The minimum size of a TCP header is 20 bytes. However, optional fields can increase this size to a maximum of 60 bytes. These options provide additional functionalities and are only included when needed.

TCP's Role in Reliable Data Transfer:

The TCP header plays a vital role in TCP's reliable data transfer by:

  • Establishing and maintaining connections: The SYN and ACK flags coordinate the three-way handshake for connection setup, while FIN flags handle connection closure.
  • Ordering data: Sequence numbers ensure data arrives in the correct order.
  • Controlling flow: The window size mechanism prevents the sender from overwhelming the receiver's capacity.
  • Detecting errors: The checksum validates data integrity.

Related Articles