Three Way Handshake & TCP Overview

This is how a TCP connection is established and data starts to get across, but wait what is SYN, ACK ?

These are "flags", just bits that are set to 1 while crafting the corresponding TCP packet.

A TCP packet is made up of header and data. Where Header has a fixed set of fields:

A TCP segment consists of a segment header and a data section. The segment header contains 10 mandatory fields, and an optional extension field (Options, pink background in table).

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

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

  • Sequence number (32 bits): 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 next sequence number that the sender of the ACK is expecting. This acknowledges receipt of all prior bytes (if any). The first ACK sent by each end acknowledges the other end's initial sequence number itself, but no data.

  • Data offset (4 bits): Specifies the size of the TCP header in 32-bit words. The minimum size header is 5 words and the maximum is 15 words thus giving the minimum size of 20 bytes and a maximum of 60 bytes, allowing for up to 40 bytes of options in the header. This field gets its name from the fact that it is also the offset from the start of the TCP segment to the actual data.

  • Reserved (3 bits): For future use and should be set to zero.

  • Flags (9 bits) Contains 9 1-bit flags (control bits) as follows:

NS (1 bit): ECN-nonce - concealment protection CWR (1 bit): Congestion window reduced (CWR) flag is set by the sending host to indicate that it received a TCP segment with the ECE flag set and had responded in congestion control mechanism. ECE (1 bit): ECN-Echo has a dual role, depending on the value of the SYN flag. It indicates: 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. Only the first packet sent from each end should have this flag set. Some other flags and fields change meaning based on this flag, and some are only valid when it is set, and others when it is clear. FIN (1 bit): Last packet from sender Window size (16 bits): The size of the receive window, which specifies the number of window size units that the sender of this segment is currently willing to receive.

  • Checksum (16 bits): The 16-bit field is used for error-checking of the TCP header, the payload, and an IP pseudo-header.

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

So, SYN and ACK are the segments that have the respective flags turned on i.e. set to 1.

Last updated