TCP Handshakes

Mahendra RaoMahendra Rao
4 min read

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?

  1. Ensures a Reliable Connection – Confirms both parties are ready to communicate.

  2. Prevents Packet Loss – Helps avoid missing or corrupted data.

  3. 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:

  1. You call your friend (SYN) πŸ“ž

  2. Your friend picks up and greets you (SYN-ACK) πŸ‘‹

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

SYN Step

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

SYN-ACK Step

3️⃣ ACK (Acknowledge)

  • The client responds with an ACK, confirming the connection is successfully established.

πŸ“œ Example Packet:

Client β†’ Server: ACK, ISN = 5001

ACK Step

πŸŽ‰ 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

  1. RFC 793 – Transmission Control Protocol (TCP)

  2. "Computer Networking: A Top-Down Approach" by Kurose & Ross

  3. Cisco Networking Academy – TCP/IP Fundamentals

  4. IETF TCP/IP Standards – IETF.org

0
Subscribe to my newsletter

Read articles from Mahendra Rao directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mahendra Rao
Mahendra Rao