TCP 3-Way Handshake

1. What Is a 3-Way Handshake in TCP?

It’s the process that establishes a reliable connection before data transfer begins. This three-step exchange (SYN, SYN-ACK, ACK) ensures both devices are synchronized and ready to communicate.

Before two devices can communicate using the TCP protocol, they must first establish a TCP session. This ensures that both sides are ready to send and receive data in a reliable and ordered manner.

To do this, TCP uses a structured process called the 3-Way Handshake, which consists of three distinct steps:

  1. SYN – The client introduces itself and initiates the connection.
  2. SYN-ACK – The server replies, acknowledging the client and sharing its own connection parameters.
  3. ACK – The client confirms, and the TCP session is fully established.
What Is a 3 Way Handshake illustrated with a client and server exchanging SYN, SYN-ACK, and ACK messages
Figure 1 – TCP 3-Way Handshake

Think of it like two people calling each other by name, confirming they can hear one another, and agreeing to start talking.

2. Steps of the 3 Way Handshake in TCP

The TCP handshake involves three distinct steps between the client (initiator) and the server (responder).

Step 1 – Client Sends SYN (Connection Request)

The client starts by sending a SYN packet to the server. This packet includes its Initial Sequence Number (ISN), which marks the starting point for the byte stream.

The client sends a SYN to the server with ISN=1000 for example.

Diagram showing the SYN phase of the TCP 3-way handshake, where the client initiates a connection by sending a synchronization (SYN) packet.
Figure 2 – SYN Phase of the TCP 3-Way Handshake

Step 2 – Server Replies with SYN-ACK

The server responds with a SYN-ACK packet. It has two parts:

  • It sends its own ISN, say 2000
  • It acknowledges the client’s SYN by replying with ACK = 1001
TCP 3-Way Handshake Step 2 – Server responds with SYN-ACK, sending sequence number 2000 and acknowledging client's SYN=1000 with ACK=1001
Figure 3 – SYN-ACK Phase of the TCP 3-Way Handshake

Step 3 – Client Sends Final ACK

The client completes the handshake by sending an ACK (acknowledge) packet. This confirms the server’s SYN-ACK and establishes the connection. Data transfer can now begin.

The client sends an ACK with acknowledgment number 2001 (Server’s ISN + 1).

Diagram showing the ACK phase of the TCP 3-way handshake, where the client acknowledges the server's response to complete the connection establishment.
Figure 4 – ACK Phase of the TCP 3-Way Handshake

3. TCP Connection Termination

After data transfer is complete, TCP ensures a graceful termination of the connection between the client and server. This structured process prevents data loss and avoids leaving one side unaware of the closure. The connection termination follows four distinct steps.

Step 1 – Client Sends FIN

The client signals its intent to terminate the connection by sending a TCP segment with the FIN (Finish) flag set. This indicates that the client has no more data to send.

The client sends a FIN segment to the server, signaling the end of its data transmission !

Diagram showing the FIN phase during TCP connection termination, illustrating how a device initiates the session closure with a finish (FIN) packet.
Figure 5 – FIN Phase of TCP Connection Termination

Step 2 – Server Acknowledges FIN

The server acknowledges the client’s FIN request by responding with an ACK (Acknowledgment) segment. This confirms that the server has received the client’s request to terminate the connection.

The server sends an ACK segment to the client in response to the FIN request.

Diagram showing the server's ACK phase during TCP connection termination, illustrating how the server acknowledges the client's termination request.
Figure 6 – ACK Phase (Server Acknowledges FIN)

Step 3 – Server Sends Its Own FIN

After acknowledging the client’s FIN, the server sends its own TCP segment with the FIN flag set. This signals that the server has finished sending data and is ready to close its side of the connection.

The server sends a FIN segment to the client, indicating its readiness to terminate the connection.

Diagram showing the server's FIN phase during TCP connection termination, where the server initiates its own session closure with a finish (FIN) packet.
Figure 7 – FIN Phase (Server Initiates Termination)

Step 4 – Client Sends Final ACK

The client acknowledges the server’s FIN request by sending an ACK segment. This final acknowledgment completes the connection termination process, and the connection is fully closed.

The client sends an ACK segment to confirm the server’s FIN.

Diagram showing the ACK phase during TCP connection termination, illustrating how the final acknowledgment is sent to complete the session closure.
Figure 8 – ACK Phase (Client Acknowledges Server’s FIN)

4. Conclusion

The TCP 3-Way Handshake is the process that establishes a reliable TCP connection between two devices.

By exchanging SYN, SYN-ACK, and ACK, both sides synchronize their sequence numbers and confirm they are ready to communicate.

This handshake is the foundation of TCP reliability, ensuring ordered delivery, error recovery, and proper flow control before any data transfer begins.