TCP Working: 3-Way Handshake & Reliable Communication
How the TCP 3-Way Handshake Ensures Reliable Network Communication
What If Data Had No Rules?
Imagine sending a message to a friend, but:
Parts of the message arrive out of order 🤦♀️
Some words never arrive
You don’t even know if your friend received it
That’s exactly what would happen on the internet without rules.
The internet is inherently unreliable — packets can be lost, duplicated, delayed, or arrive out of order. To solve this problem, we need a protocol that ensures reliable communication.
That protocol is TCP (Transmission Control Protocol).
What Is TCP and Why Is It Needed?
TCP is a transport-layer protocol that ensures data is:
Delivered correctly
Delivered completely
Delivered in the correct order
TCP is used when accuracy matters more than speed.
Examples where TCP is critical:
Web browsing (HTTP/HTTPS)
Emails
File downloads
Online payments
Login systems
Without TCP, these applications would break very easily.
Problems TCP Is Designed to Solve
TCP was created to solve several key problems:
Packet Loss
Data packets may disappear while traveling across the network.Out-of-Order Delivery
Packets may arrive in the wrong order.Duplicate Packets
The same packet may arrive more than once.No Confirmation
The sender might not know whether the data was received.
TCP handles all of these problems automatically.
What Is the TCP 3-Way Handshake?
Before any data is sent, TCP first establishes a connection between the client and the server.
This connection setup is called the TCP 3-Way Handshake.

It ensures that:
Both sides are ready
Both sides can send and receive data
Initial communication parameters are agreed upon
Step-by-Step: SYN, SYN-ACK, ACK
Step 1: SYN (Synchronize)
The client sends a message to the server saying:
“I want to start a connection.”
This packet contains:
A SYN flag
An initial sequence number
Step 2: SYN-ACK (Synchronize + Acknowledge)
The server responds:
“I received your request, and I’m ready too.”
This packet contains:
SYN flag (server’s sequence number)
ACK flag (acknowledging the client’s SYN)
Step 3: ACK (Acknowledge)
The client sends the final message:
“Acknowledged. Let’s start sending data.”
Now the connection is established.
How Data Transfer Works in TCP
Once the connection is established, data transfer begins.
TCP breaks data into segments, and each segment has:
A sequence number
An acknowledgement number
What Are Sequence Numbers?
Sequence numbers help TCP:
Track the order of packets
Detect missing data
Reassemble data correctly
What Are Acknowledgements (ACKs)?
ACKs tell the sender:
“I have received data up to this point.”
Diagram Idea: TCP Data Transfer
Sender → Seq 1 → Receiver
Sender → Seq 2 → Receiver
Receiver → ACK 3 → Sender
How TCP Ensures Reliability, Order, and Correctness
TCP uses multiple mechanisms to ensure reliable communication:
1. Acknowledgements
Every chunk of data must be acknowledged.
2. Retransmission
If an ACK is not received in time, TCP resends the data.
3. Ordering
Sequence numbers ensure data is delivered in the correct order.
4. Error Checking
TCP checks for corrupted data and requests retransmission if needed.
Packet Loss and Retransmission
If a packet is lost:
The receiver notices a missing sequence number
ACK is not sent
Sender waits for a timeout
Sender retransmits the missing packet

How a TCP Connection Is Closed
TCP does not just stop communication suddenly. It closes connections gracefully.
Connection termination uses:
FIN (Finish)
ACK (Acknowledge)
Simple Explanation:
“I’m done sending data.”
Basic Closing Steps:
One side sends FIN
The other side sends ACK
The other side sends its own FIN
Final ACK is sent
Now the connection is fully closed.

Why TCP Matters for Web Developers
As a web developer, understanding TCP helps you:
Debug slow network issues
Understand why retries happen
Know why some apps prioritize speed over reliability
Build better mental models of how the web works
Final Thoughts
TCP is the backbone of reliable communication on the Internet.
The 3-way handshake ensures a safe connection setup
Sequence numbers and ACKs ensure ordered delivery
Retransmissions handle packet loss
Graceful termination ensures clean connection closure
Once you understand TCP, many higher-level concepts in web development start to make much more sense.




