TCP Working: 3-Way Handshake & Reliable Communication
How two computers establish trust and exchange data without losing a single byte

1. What is TCP
Every time you open Instagram, your data travels through chaos yet it arrives perfectly. That’s TCP.
TCP (Transmission Control Protocol) it is safe and reliable.
Think of it like a postal service that tracks every package.
2. Problems TCP is designed to solve
Internet is chaotic:
• Sometimes Routers drop packets when they are busy
• Some packets arrive late
• Some arrive twice
• Some never arrive
if you send
A B C D E
receiver might get
B A D E C
To solve this problems TCP is designed.
3. What is the TCP 3-Way Handshake
Let’s say:
Your browser wants to talk to the google.com
Before sending any HTTP data, TCP says, We must synchronize our counting systems.
Why?
Because every byte is numbered.
4. 3-way handshake using a simple conversation analogy
You are student of Hitesh sir’s Web dev cohort and you want to join a live Zoom class.
Because it’s paid:
• Only real students are allowed
• No fake students
• No ghost connections
So Zoom and ChaiCode cohort platform runs a TCP 3-way handshake before letting you in.
Step 1 - You go to the ChaiCode app and register for class and then click on the Join Metting
Now Zoom app sends:
Hi Hitesh sir i want to join the class, my meeting id start from 4893.
Please create a fresh connection for me.
But you are still outside the class.
Step 2 - Zoom server replies (SYN-ACK)
Zoom server replies:
I got your 4893.
I created a temporary seat for you 5844.
This proves:
• The class is live
• The server listens you
• A temporary slot is reserved
But Zoom is still not sure if you are real you could be hacker, duplicate click.
Step 3 - You confirm (ACK)
Your Zoom app replies:
I confirm seat 5844.
Now the server knows, this student is real and connected right now.
Your seat becomes permanent.
You enter the live class and Hitesh sir say’s
Hanji kaise ho aap sab ?

5. Sequence numbers and acknowledgements at a high level
When data moves on the internet, it is broken into small pieces called packets.
These packets can arrive out of order, arrive twice or get lost.
a. Sequence Number (SN)
sequence number is the position of this data in the full message.
TCP does not number packets it numbers bytes.
If i send:
Tejas
It becomes:
| Byte | Data |
| 1005 | T |
| 1006 | e |
| 1007 | j |
| 1008 | a |
| 1009 | s |
This lets the receiver reorder data, detect missing parts and detect duplicates.
b. Acknowledgement Number (ACK)
An ACK does not say i got this packet It say i have received everything up to this point.
If the receiver sends:
ACK = 1010
This is powerful because one number confirms many packets and gaps are easy to detect.

6. How data transfer works in TCP
Connection is establishment happen.
Data is broken into bytes
Bytes are sent in packets
Receiver sends ACK’s
Lost data is re-sent
Data is aligned perfectly
7. How TCP handles packet loss and retransmission
TCP numbers every byte, waits for acknowledgements, and if something isn’t acknowledged, it sends it again.

8. Connection termination using FIN and ACK
Hitesh sir and Piyush sir are talking on a phone call.
Hitesh sir don’t just hang up suddenly they make sure the Piyush sir is finished too.
This is exactly how TCP closes a connection.
Hitesh sir: I’m done talking (FIN)
Hitesh sir says, Piyush sir i’m done I won’t say anything more.
Hitesh sir stays on the call just quiet now.
Piyush sir: I heard you (ACK)
Piyush sir replies okay, I heard you But Piyush sir may still be talking.
Piyush sir: Now I’m also done (FIN)
After finishing his last words, Piyush sir say Now I’m done too.
Hitesh sir: Got it (ACK)
Hitesh sir: replies: Got it. I heard you.
Now Hitesh sir and Piyush sir know, the conversation is truly over.
They hang up safely.

9. Final thought:
TCP is the reason the chaotic internet feels reliable it connects, delivers, fixes, and closes conversations so perfectly that apps never see the mess underneath.

