TCP Handshakes


Understanding TCP Handshakes: How the Internet Establishes Reliable Connections
π Introduction
Have you ever wondered how your device successfully connects to a website or an online service? Behind the scenes, a fascinating process called the TCP 3-Way Handshake ensures a reliable connection before data starts flowing. This handshake is the internet's way of saying "Hello! Can we talk?"
In this article, we'll explore:
What is the TCP 3-Way Handshake and why is it important?
A visual guide to how TCP handshakes work
How sequence numbers and ACKs make connections reliable
Let's dive in! π
π The TCP 3-Way Handshake: What It Is and Why It's Important
TCP (Transmission Control Protocol) is one of the core protocols of the internet, designed for reliable, ordered, and error-checked communication. Before two devices can exchange data over TCP, they must establish a connection using the 3-Way Handshake.
π Why Does the 3-Way Handshake Matter?
Ensures a Reliable Connection β Confirms both parties are ready to communicate.
Prevents Packet Loss β Helps avoid missing or corrupted data.
Synchronizes Sequence Numbers β Ensures ordered delivery of data packets.
Without this process, network communication would be unpredictable, leading to broken connections and missing data.
Let's break it down step by step. π½
π "How the Internet Says Hello": A Visual Guide to TCP Handshakes
Imagine you are making a phone call to a friend. Before you start talking, you both need to acknowledge each other:
You call your friend (SYN) π
Your friend picks up and greets you (SYN-ACK) π
You confirm you heard them (ACK) β
This is exactly how TCP handshakes work!
π₯οΈ The 3 Steps of the TCP 3-Way Handshake
1οΈβ£ SYN (Synchronize)
The client (your computer) sends a SYN (synchronize) request to the server, indicating its intent to establish a connection.
It also sends an Initial Sequence Number (ISN), a unique identifier for tracking data.
π Example Packet:
Client β Server: SYN, ISN = 1000
2οΈβ£ SYN-ACK (Synchronize-Acknowledge)
- The server acknowledges the clientβs request with SYN-ACK, sending its own ISN and confirming receipt of the clientβs SYN.
π Example Packet:
Server β Client: SYN, ISN = 5000 | ACK, ISN = 1001
3οΈβ£ ACK (Acknowledge)
- The client responds with an ACK, confirming the connection is successfully established.
π Example Packet:
Client β Server: ACK, ISN = 5001
π Now the connection is open! Data can start flowing securely between the client and the server.
πΉ Key Takeaway: The 3-Way Handshake ensures both devices agree on connection parameters before data transfer begins.
βοΈ Reliable Connections in TCP: How Sequence Numbers and ACKs Work
TCP guarantees data integrity by using Sequence Numbers (ISN) and Acknowledgments (ACKs). Here's how:
πΉ Sequence Numbers
Every TCP packet has a sequence number that helps order data properly. The Initial Sequence Number (ISN) is randomly assigned when a connection starts and increases with each transmitted byte.
π Example:
Client sends ISN = 1000
Next packet starts at 1001, then 1002, and so on.
πΉ Acknowledgment (ACK) Numbers
For each received packet, the receiver sends an ACK number, indicating which byte it expects next. If a packet is lost, TCP can retransmit it.
π Example:
Client sends data up to byte 2000
Server replies ACK = 2001, meaning "I received everything up to 2000. Send more!"
πΉ Why Does This Matter?
Prevents packet loss and ensures correct ordering.
Helps with congestion control by adjusting the data flow.
Guarantees data delivery, making TCP ideal for web browsing, emails, and file transfers.
π Conclusion
The TCP 3-Way Handshake is a crucial process that ensures reliable communication between devices on the internet. It establishes a secure connection, synchronizes data flow, and prevents packet loss.
π₯ Key Takeaways:
TCP uses a 3-step handshake (SYN β SYN-ACK β ACK) to establish connections.
Sequence Numbers keep track of data packets, ensuring ordered delivery.
ACK numbers confirm data receipt and request the next packet.
This process makes TCP the backbone of reliable internet communication.
π Now that you understand TCP handshakes, youβre one step closer to mastering networking fundamentals!
π References
RFC 793 β Transmission Control Protocol (TCP)
"Computer Networking: A Top-Down Approach" by Kurose & Ross
Cisco Networking Academy β TCP/IP Fundamentals
IETF TCP/IP Standards β IETF.org
Subscribe to my newsletter
Read articles from Mahendra Rao directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
