TCP Three-Way Handshake
You'll learn how TCP establishes a reliable connection before any data transfer begins, using a three-message exchange that synchronizes both endpoints.
What Is the Three-Way Handshake?
Before a TCP connection can transfer data, the client and server must agree to communicate and exchange critical setup information—specifically, sequence numbers that track bytes sent in each direction. This happens through a three-step process called the three-way handshake.
Think of it like two people greeting each other on a walkie-talkie: "Can you hear me?" → "Yes, can you hear me?" → "Yes!" Only after this exchange can they have a real conversation.
The Three Steps
1. SYN (Synchronize)
The client sends a TCP segment with the SYN flag set and includes an initial sequence number (ISN). This says, "I want to connect, and I'll start counting my bytes from this number."
2. SYN-ACK (Synchronize-Acknowledge)
The server responds with a segment that has both SYN and ACK flags set. It includes:
- Its own initial sequence number
- An acknowledgment number (client's ISN + 1)
This means, "I accept your connection, here's my starting number, and I received yours."
3. ACK (Acknowledge)
The client sends back a segment with just the ACK flag set, acknowledging the server's sequence number (server's ISN + 1). This confirms, "Got it! We're connected."
After these three messages, both sides know each other's starting sequence numbers, and the connection is established—ready to transfer data reliably.
Key Takeaway: The TCP three-way handshake uses SYN, SYN-ACK, and ACK messages to establish a connection and synchronize sequence numbers between client and server before any application data is transmitted.