Introduction to Connection Establishment
The Transmission Control Protocol (TCP) is a strictly connection oriented protocol. This means that before a client and a server can exchange a single byte of actual application data, they must formally establish a reliable virtual connection.
This connection setup process is known as the 3 Way Handshake. Its primary purpose is to synchronize sequence numbers, allocate buffer memory, and mutually confirm that both devices are ready to communicate.
The Three Steps in Detail
The handshake relies on two specific control flags located in the TCP header: the SYN (Synchronize) flag and the ACK (Acknowledge) flag.

A visual representation of the SYN, SYN-ACK, and ACK process between a client and a server.
Step 1: SYN (Client to Server)
The process begins when the Client wants to initiate a connection with the Server. The Client creates a TCP segment with the SYN flag set to 1.
Crucially, the Client generates a random Initial Sequence Number (ISN) and includes it in this segment. This segment does not carry any actual application data, but it mathematically consumes one sequence number.
Step 2: SYN ACK (Server to Client)
The Server receives the SYN segment. If the Server is willing to accept the connection, it allocates buffer memory for the incoming data and replies with a segment of its own.
In this reply, both the SYN flag and the ACK flag are set to 1. The Server acknowledges the Client's request by setting the Acknowledgement Number to the Client's ISN plus 1. Furthermore, the Server generates its own completely random Initial Sequence Number and includes it in the segment.
Step 3: ACK (Client to Server)
The Client receives the SYN ACK from the Server. The Client now allocates its own buffer memory and sends a final acknowledgement back to the Server.
In this final segment, the ACK flag is set to 1, and the SYN flag is set to 0. The Acknowledgement Number is set to the Server's ISN plus 1. Unlike the first two steps, this third step is allowed to carry the very first payload of actual application data (such as an initial web request).
A Concrete Mathematical Example
To make this perfectly clear for exams, let us trace an exact mathematical example of sequence numbers during the handshake.
- Setup: Assume the Client randomly chooses an ISN of 1000. Assume the Server randomly chooses an ISN of 5000.
- Step 1 (SYN): Client sends: SYN=1, Sequence Number=1000.
- Step 2 (SYN ACK): Server sends: SYN=1, ACK=1, Sequence Number=5000, Acknowledgement Number=1001. (The 1001 explicitly tells the client: I successfully received byte 1000, I am now waiting for byte 1001).
- Step 3 (ACK): Client sends: ACK=1, Sequence Number=1001, Acknowledgement Number=5001. (The 5001 explicitly tells the server: I successfully received byte 5000, I am now waiting for byte 5001).
Why Exactly Three Steps?
A highly common exam question is why a simple two step handshake is insufficient. If the process only involved Step 1 (SYN) and Step 2 (SYN ACK), a critical problem arises: The Server has no mathematical way of knowing if its SYN ACK ever actually reached the Client.
If the SYN ACK is lost in the network, the Server would allocate memory and sit waiting indefinitely for data over a connection the Client never successfully opened. The third step (ACK) provides mandatory mutual confirmation, ensuring both the Client and Server absolutely know the other side is completely ready.
Connection Termination (The 4 Way Handshake)
Just as TCP requires a formal process to open a connection, it requires a formal process to politely close it. Because TCP is full duplex (meaning data flows in both directions simultaneously), each direction must be closed entirely independently.
This requires four steps: The Client sends a FIN (Finish) segment, and the Server sends an ACK. Then, when the Server is completely done sending its own data, the Server sends a FIN segment, and the Client sends a final ACK.
