Skip to main content

TCP & UDP Headers

Headers are essential components of network protocols, providing the necessary information for data transfer across networks. Both TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) have their unique headers, tailored to the specific requirements of each protocol.

TCP & UDP Header

TCP & UDP Header

TCP Header​

A typical TCP header is 20 bytes long without options but can be longer if options are included. The TCP header is more complex than the UDP header because it provides additional features for reliable data transfer.

Source Port (16 bits)​

  • Identifies the port number on the sender's side.

  • Helps direct segments to the correct application on the sender side.

Destination Port (16 bits)​

  • Identifies the port number on the receiver's side.

  • Ensures the packet is delivered to the correct application on the receiver side.

Sequence Number (32 bits)​

  • Keeps track of the order of bytes sent by TCP.

  • Ensures data is reassembled in the correct order at the receiver.

Acknowledgment Number (32 bits)​

  • Used to acknowledge the receipt of data.

  • Indicates the next byte the sender expects to receive, ensuring reliable delivery.

Data Offset (4 bits)​

  • Specifies the length of the TCP header.

  • Indicates where the actual data begins, following the header.

Reserved (3 bits)​

  • Reserved for future use.

  • Currently set to zero.

Flags (9 bits)​

Flags are control bits, each 1 bit in size. They play critical roles in managing TCP connections and data flow.

  • NS: ECN-nonce concealment protection.

  • CWR: Congestion Window Reduced, used to manage congestion control.

  • ECE: ECN-Echo, signals network congestion.

  • URG: Urgent pointer field is significant.

  • ACK: Acknowledgment field is significant, confirming receipt of data.

  • PSH: Push function, indicates data should be pushed to the receiving application immediately.

  • RST: Reset the connection, used to reinitialize or abort a connection.

  • SYN: Synchronize sequence numbers, used in connection establishment.

  • FIN: No more data from the sender, used to terminate a connection.

Window Size (16 bits)​

  • Specifies the amount of data (in bytes) that the receiver is willing to accept.

  • Crucial for flow control, preventing the sender from overwhelming the receiver.

Checksum (16 bits)​

  • Used for error-checking the TCP header and data.

  • Ensures data integrity; if the receiver's calculated checksum matches the header, the segment is not corrupted.

Urgent Pointer (16 bits)​

  • Indicates the end of the urgent data within a segment.

  • Only significant if the URG flag is set.

Options (variable length)​

  • Optional field for additional features.

  • Can be used for specifying Maximum Segment Size (MSS), window scaling, and timestamps.

Padding (variable length)​

  • Added to ensure the TCP header is a multiple of 32 bits.

  • Ensures proper alignment and processing.

UDP Header​

The UDP header is simpler and fixed at 8 bytes, reflecting the protocol’s focus on speed and low overhead. UDP provides basic functionality without the complexity of connection management and error recovery found in TCP.

Source Port (16 bits)​

  • Identifies the port number on the sender's side.

  • Optional; if not used, it is set to zero.

Destination Port (16 bits)​

  • Identifies the port number on the receiver's side.

  • Ensures the packet is directed to the correct application.

Length (16 bits)​

  • Specifies the total length of the UDP header and data.

  • The minimum value is 8 bytes, which accounts for the header only.

Checksum (16 bits)​

  • Used for error-checking the header and data.

  • Provides a basic level of integrity check.