0
0
Computer Networksknowledge~6 mins

Three-way handshake in Computer Networks - Full Explanation

Choose your learning style9 modes available
Introduction
Starting a conversation between two computers over the internet is tricky because both sides need to agree to talk and be ready. Without a clear way to open this communication, messages could get lost or misunderstood. The three-way handshake solves this by making sure both computers say hello and confirm they are ready before exchanging data.
Explanation
SYN: Initiating connection
The first computer sends a special message called SYN to the second computer. This message says, "I want to start talking and here is my initial sequence number." It is like knocking on the door to ask if the other side is ready.
The SYN message starts the connection by asking to communicate and sharing a starting point.
SYN-ACK: Acknowledging and agreeing
The second computer replies with a SYN-ACK message. This means it received the first message and agrees to connect. It also sends its own sequence number to the first computer. This step is like the other person opening the door and saying, "I’m ready too."
SYN-ACK confirms the request and shares readiness from the second computer.
ACK: Final confirmation
The first computer sends an ACK message back to the second computer. This message confirms it received the SYN-ACK and the connection is now fully established. After this, both computers can start sending actual data safely.
The ACK message completes the handshake and opens the communication channel.
Real World Analogy

Imagine two friends planning to meet. One calls and says, "Are you ready to meet?" The other replies, "Yes, I’m ready and here’s where I’ll be." Finally, the first friend says, "Great, I’m on my way!" Only after this exchange do they actually meet.

SYN: Initiating connection → First friend calling to ask if the other is ready to meet
SYN-ACK: Acknowledging and agreeing → Second friend replying that they are ready and sharing meeting details
ACK: Final confirmation → First friend confirming they received the reply and are coming
Diagram
Diagram
Computer A          Computer B
   │                    │
   │ ---- SYN ---------> │
   │                    │
   │ <--- SYN-ACK ------ │
   │                    │
   │ ------ ACK -------> │
   │                    │
Connection Established
This diagram shows the three messages exchanged between two computers to establish a connection.
Key Facts
SYNA message sent to start a connection and share the initial sequence number.
SYN-ACKA message acknowledging the SYN and agreeing to connect, also sharing a sequence number.
ACKA message confirming receipt of SYN-ACK and completing the connection setup.
Sequence NumberA number used to keep track of the order of messages during communication.
Connection EstablishmentThe process of both computers agreeing to communicate before sending data.
Common Confusions
Believing the handshake happens instantly without message exchange.
Believing the handshake happens instantly without message exchange. The handshake requires three separate messages exchanged in order to ensure both sides are ready.
Thinking the handshake sends actual data.
Thinking the handshake sends actual data. The handshake only sets up the connection; actual data transfer happens after it completes.
Summary
The three-way handshake is a step-by-step greeting between two computers to start communication safely.
It involves sending SYN, receiving SYN-ACK, and replying with ACK messages in order.
This process ensures both sides are ready and agree on how to send data.