In order to establish a TCP connection, a three-way (or 3-step) handshake occurs:
SYN: The active open is performed by the client sending the SYN to the server. The clients sets the segment’s sequence number to a random value A.
SYN-ACK: In response , the server replies with a SYN-ACK. The acknowledgment number is set to one more than the received sequence number i.e. A+1, and the sequence number that the server chooses for the packet is another random number, B.
ACK: Finally, the client sends an ACK back to the server. The sequence number is set to the received acknowledgement value i.e. A+1, and the acknowledgement number is set to one more than the received sequence number i.e. B+1.