TCP 3-Way Handshake

1. Introduction

The TCP 3-Way Handshake is the process that establishes reliable communication in TCP/IP networks. It ensures that both devices involved in the communication are synchronized and ready for data exchange. This handshake also sets important parameters like sequence numbers to maintain data integrity.

Why It Matters: Without this handshake, reliable data transfer would not be possible. It is a core concept in networking, essential for troubleshooting, understanding network performance, and enhancing security.

Real-World Example: Think of the handshake as a quick “hello” between two devices, confirming they are ready to talk before starting a conversation.

TCP three way handshake

2. Steps of the 3-Way Handshake

SYN Phase

The client begins by sending a SYN (synchronize) packet to the server. This packet includes an initial sequence number (ISN), signaling the client’s intention to establish a connection.

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

SYN Phase

SYN-ACK Phase

The server responds with a SYN-ACK (synchronize-acknowledge) packet. This packet acknowledges the client’s request and includes the server’s ISN.

The server sends a SYN-ACK with ISN=2000 and acknowledgment number 1001 (Client’s ISN + 1).

SYN ACK Phase

ACK Phase

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).

ACK Phase

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.

FIN Phase

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.

TCP Connection Termination FIN Phase

ACK Phase (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.

TCP Connection Termination Server ACK Phase

FIN Phase (Server Initiates Termination)

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.

TCP Connection Termination Server FIN Phase

ACK Phase (Client Acknowledges Server’s FIN)

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.

TCP Connection Termination ACK Phase