During handshaking, two hosts agree on protocols to be followed during their communication prior to the communication itself. In TCP, a three-way handshake takes place during connection establishment.
The steps below are the steps involved in the connection establishment:
The client (a process that initiates the communication) sends a segment. The segment contains a randomly generated sequence number, and the SYN flag is set.
Upon receiving the segment, the server replies with a segment that has the server’s sequence number, its window size, an acknowledgment, and the SYN flag set.
The client sends its sequence number, its window size, and an acknowledgment.
The acknowledgment is always equal to the received segment’s sequence number plus one.
The illustration below visually represents the steps above: