TCP & Three way handshake
Second-year Computer Science student passionate about becoming a Software Development Engineer. Currently focused on Data Structures & Algorithms in C++, JavaScript, and building strong problem-solving skills. I enjoy learning by building projects and preparing for top tech company interviews.
What was the problem? Let’s think about one scenario.
First imagine sending data with NO rules ! wooh!
Suppose you send your friend 5 WhatsApp messages.
But your friend receives:
message 3 first
then message 1
message 2 never comes
message 4 comes twice
You will be confused right?
Conversation makes no sense.
This same problem happens on internet if there are no rules.
Computers send data in small pieces. If there is no system:
some data gets lost
some comes late
some comes in wrong order
some comes twice
Total chaos.
So internet needed a system that manages everything properly.
That system is TCP.
What is TCP?
TCP = Transmission Control Protocol
In very simple words:
TCP is a set of rules that makes sure data goes safely from one computer to another.
It makes sure:
data reaches
reaches in correct order
nothing missing
nothing duplicate
connection is proper before sending
Real life example:
Think TCP like a courier service with tracking.
You send 10 items.
Courier tracks:
which box sent
which delivered
if one lost → send again
Same work TCP does for internet data.
Whenever you:
open website
watch YouTube
login to Instagram
download file
TCP is working behind the scenes.
Problems TCP solves
Internet is not perfect. It's like Mumbai traffic ..haha!! Anything can happen.
1. Data loss
Packets can get lost while travelling.
Like courier lost in traffic.
2. Wrong order
Packet 5 may reach before packet 1.
Like receiving page 5 of book before page 1.
3. Duplicate packets
Same packet may come twice.
Like same parcel delivered twice.
4. Receiver not ready
Sender sending but receiver busy.
Like calling someone when phone off.
5. No confirmation
Sender doesn't know data reached or not.
TCP solves all this.
It makes communication reliable.
Before sending data — TCP checks connection first
You don't start talking suddenly.
First you say:
"Hello, free to talk?"
TCP also does same.
Before sending data it creates connection.
This is called:
TCP 3-way handshake
Real life example: phone call.
You call → they pick → you confirm → then talk.
Three steps:
SYN
SYN-ACK
ACK
Step 1: SYN (Client → Server)
Client sends:
"Hello server, can we connect?"
This is SYN.
It also sends a starting number called sequence number.
Simple meaning:
I want to start conversation.
Real example:
Like you texting:
"Hey online?"
Step 2: SYN-ACK (Server → Client)
Server replies:
"Yes I am here and I got your message"
This is SYN-ACK.
Meaning:
SYN → server also ready
ACK → received your message
Real example:
Friend replies:
"Yes, tell me"
Step 3: ACK (Client → Server)
Client sends:
"Ok great, let's start"
This is ACK.
Now connection is established.
Now actual data can start.
Real example:
Now both start chatting properly.
How data travels using TCP
TCP breaks data into small pieces called segments.
Each piece has number.
Example:
Sending 5-page PDF.
TCP sends like:
page 1
page 2
page 3
Each numbered.
Receiver checks numbers and arranges correctly.
After receiving, receiver sends ACK.
Meaning:
"Yes I got till page 3"
If sender doesn't get ACK?
It sends again.
Like courier tracking.
How TCP ensures reliability
TCP is very strict..Just like our BigBoss!! haha!!
Sequence numbers
Every packet numbered.
So order stays correct.
Acknowledgement
Receiver confirms data.
No confirmation → resend.
Retransmission
If packet lost → send again.
Error checking
If data damaged → resend.
Flow control
If receiver slow → sender slows down.
Like teacher giving notes slowly so students can write.
Result:
correct + safe + ordered delivery.
How TCP connection closes
After work finished, connection must close properly.
Not suddenly.
TCP uses:
FIN and ACK
Example: ending phone call.
One side:
"Ok I am done"
(FIN)
Other side:
"Ok bye"
(ACK)
Then other side also sends FIN.
Final ACK happens.
Connection closed safely.
Final simple summary
TCP is like a responsible manager of internet.
It:
creates connection first
sends data carefully
checks delivery
resends if lost
keeps order correct
closes properly
Without TCP:
internet would be messy and confusing
With TCP:
everything works smooth and reliable
And that's why TCP is one of the most important protocols on internet.
So if you're willing to send me some "MONEY" , send it to me via TCP, not UDP!
Just kidding!