TCP Working: 3-Way Handshake & Reliable Communication

When we use the internet—open a website, send a WhatsApp message, upload a file—everything feels instant and smooth.
But behind the scenes, data is flying around the network in small pieces, and without rules, things can get messy very fast.
Let’s understand how TCP keeps things clean, reliable, and in order, without going deep into boring packet-level details.
What is TCP and Why Do We Need It?
Imagine you’re sending a 10-page physical letter to a friend via a local courier. If you just throw all 10 pages into 10 different envelopes and send them, a few things could go wrong:
Page 3 might get lost.
Page 5 might arrive before Page 1.
The ink might smudge, making Page 8 unreadable.
In the world of the internet, TCP (Transmission Control Protocol) is like that "Super-Reliable Courier" who promises three things:
Everything arrives.
Everything is in the right order.
Nothing is corrupted.
Without TCP, the internet would be a mess. You’d click on a photo of a Biryani, and the top half might show a pizza because the data got mixed up!
Problems TCP Is Designed to Solve
TCP exists because the internet has real problems:
1. Data Can Get Lost
Networks are not perfect. Routers crash. Signals drop.
2. Data Can Arrive Out of Order
One packet might take a shortcut, another might take the long road.
3. Data Can Get Duplicated
Sometimes the same packet arrives twice.
4. Sender Doesn’t Know If Receiver Got the Data
Without confirmation, the sender is clueless.
TCP solves all of these.
What is the TCP 3-Way Handshake
Before TCP starts sending your actual data (like a photo or a reel), it doesn't just "shout" into the void. It first makes sure the other side is ready to listen. We call this the 3-Way Handshake.
Think of it like a typical phone call in India:
Step 1 (SYN): You call your friend and say, "Hello, can you hear me?" (Synchronize)
Step 2 (SYN-ACK): Your friend picks up and says, "Yes, I can hear you! Can you hear me?" (Synchronize-Acknowledge)
Step 3 (ACK): You reply, "Yes, I can hear you too. Let's talk!" (Acknowledge)
Only after these three steps are done is the "connection" established. Now, both parties know the line is clear and they are ready to exchange information.

Step-by-Step: SYN, SYN-ACK, ACK
Let’s break it down slowly.
Step 1: SYN (Client → Server)
The client says:
“I want to start a connection.”
This message is called SYN (Synchronize).
No data yet. Just a request to connect.
Step 2: SYN-ACK (Server → Client)
The server replies:
“Okay, I’m ready. I heard you.”
This message is called SYN-ACK.
Now the server also confirms it’s alive and listening.
Step 3: ACK (Client → Server)
The client replies again:
“Great, I heard you too.”
This message is called ACK (Acknowledgement).
Connection established
Both sides are ready
Data transfer can begin

How Data Transfer Works (The "Checklist" Method)
Once the call is connected, TCP doesn't just dump all the data at once. It breaks the data into small chunks called packets.
Each packet gets a Sequence Number (like page numbers in a book).
Sender: "Sending Page 1..."
Receiver: "Got Page 1! Send Page 2."
Sender: "Sending Page 2..."
If the Receiver gets Page 3 but missed Page 2, it won't say "All good." It will specifically ask, "Hey, I missed Page 2, send it again!" This is how TCP ensures Reliability.

How TCP Ensures Order & Correctness
TCP guarantees:
Correct order using sequence numbers
No duplicates
No missing data
To the application (browser, email app, etc.), everything looks clean and perfect.
That’s why developers love TCP.
How a TCP Connection Is Closed
Just like you don't just hang up the phone without saying "Bye," TCP has a formal way to end the conversation. This is usually a 4-step process using FIN (Finish) and ACK (Acknowledge) signals.
You: "I'm done talking. (FIN)"
Server: "Okay, I heard you. Let me just finish sending my last bit of data... (ACK)"
Server: "Okay, I'm done too. (FIN)"
You: "Great. Bye! (ACK)"
And just like that, the "line" is closed, and resources are freed up for the next person.




