Skip to content

TCP Segment Header

TCP

TCP headers contain the following components:

  • Source port (16 bits): Identifies the sending port

  • Destination port (16 bits): Identifies the receiving port.

  • Sequence number (32 bits)

    • Has a dual role:
      • If the SYN flag is set (1), this is the initial sequence number. The sequence number of the actual first data byte and the acknowledged number in the corresponding ACK are then this sequence number plus 1.
      • If the SYN flag is unset (0), this is the accumulated sequence number of the first data byte of this segment for the current session.
  • Acknowledgment number (32 bits)

    • If the ACK flag is set, then the value of this field is the following sequence number that the sender of the ACK is expecting.
  • Data offset (4 bits)

    • Specifies the size of the TCP header in 32-bit words. The minimum size header is five words, and the maximum is 15 words.
  • Reserved (4 bits)

    • For future use, it should be set to zero; senders should not set these, and receivers should ignore them if put in the absence of further specification and implementation.
  • Flags (8 bits)

    • Contains eight 1-bit flags (control bits) as follows:
      • CWR (1 bit): The sending host sets the congestion window reduced (CWR) flag to indicate that it received a TCP segment with the ECE flag set and responded in the congestion control mechanism.
      • ECE (1 bit): ECN-Echo has a dual role, depending on the value of the SYN flag. It indicates:
        • If the SYN flag is set (1), the TCP peer is ECN capable.
        • If the SYN flag is unset (0), a packet with the Congestion Experienced flag set (ECN=11) in its IP header was received during standard transmission. This serves as an indication of network congestion (or impending Congestion) to the TCP sender.
      • URG (1 bit): Indicates that the Urgent pointer field is significant
      • ACK (1 bit): Indicates that the Acknowledgment field is significant. All packets after the initial SYN packet sent by the client should have this flag set.
      • PSH (1 bit): Push function. Asks to push the buffered data to the receiving application.
      • RST (1 bit): Reset the connection
      • SYN (1 bit): Synchronize sequence numbers. This flag should be set only on the first packet sent from each end. Some flags and fields change meaning based on this flag; some are only valid when set, and others when clear.
      • FIN (1 bit): Last packet from sender
  • Window size (16 bits)

    • The size of the receive window specifies the number of window size units[b] that the sender of this segment is currently willing to accept.
  • Checksum (16 bits): The 16-bit checksum field checks the TCP header, payload, and IP pseudo-header for errors. The pseudo-header consists of the source IP address, the destination IP address, the TCP protocol number, and the length of the TCP headers and payload.

  • Urgent pointer (16 bits): If the URG flag is set, this 16-bit field is offset from the sequence number, indicating the last urgent data byte.

  • Options (Variable 0–320 bits, in units of 32 bits): The data offset field determines the length of this field. Options can have up to three fields: Option-Kind (1 byte), Option-Length (1 byte), and Option-Data (variable).