TCP Working: 3 Way Handshake & Reliable Communication
Understanding TCP's 3 Way Handshake for Reliable Data Transfer

A web development learner and tech enthusiast, documenting my journey into modern web development. I share what I learn, write practical coding tips, and publish beginner-friendly blogs on programming concepts and tools.
When we build websites or web apps, we constantly send data from one computer to another. A browser talks to a server, a server replies back, and data keeps moving across the internet.
But this data does not magically travel in a safe and correct way. There must be rules that decide how data is sent, received, ordered, and verified.
This is where TCP comes in.
In this article, we will slowly understand what TCP is, why it exists, what problems it solves, and how the famous 3 way handshake works. We will keep everything simple and focus on ideas instead of technical overload.
Before understanding TCP, we need to imagine what happens without it.
Suppose we send a long message from one computer to another over the internet. The message is broken into small pieces and travels through different paths. Some pieces may arrive late, some may arrive early, and some may not arrive at all.
Without rules:
Data can arrive in the wrong order
Some parts of data can be lost
The receiver may not know whether the data is complete
The sender may not know if the data was received
This would make websites unreliable. A page may load half content, images may break, or data may become corrupted.
So clearly, we need a system that controls data transfer properly.
What is TCP and why it is needed
TCP stands for Transmission Control Protocol.
TCP is a communication protocol that ensures reliable data transfer between two computers on a network. It does not send data blindly. Instead, it first creates a connection, then sends data carefully, and finally closes the connection properly.
We use TCP because:
We want data to arrive correctly
We want data in the correct order
We want to know if something goes wrong
We want both sides to agree before talking
Most important internet services like HTTP, HTTPS, email, and file transfer rely on TCP.
Problems TCP is designed to solve
TCP was designed to handle real world network problems.
First, TCP handles packet loss. If some data is lost during transfer, TCP detects it and sends the data again.
Second, TCP handles out of order delivery. Data packets may arrive in the wrong order, but TCP rearranges them correctly before giving them to the application.
Third, TCP handles duplication. If the same packet arrives twice, TCP can detect and ignore the duplicate.
Fourth, TCP handles flow control, which means it does not overwhelm the receiver with too much data at once.
Without TCP, reliable communication on the internet would not be possible.
What is the TCP 3 Way Handshake
Before sending actual data, TCP first creates a connection between the client and the server.
This connection setup process is called the 3 way handshake.
The purpose of the handshake is simple:
Both sides confirm they are ready to communicate
Both sides agree on starting sequence numbers
A reliable connection is established
This happens in three steps, which is why it is called a 3 way handshake.
Understanding the handshake using a simple conversation
We can think of the handshake like a phone call.
First, one person says, “Hello, can we talk?”
Second, the other person replies, “Yes, I can hear you.”
Third, the first person says, “Great, let’s talk.”
Only after this confirmation does the real conversation begin.
TCP works in a very similar way.
Step by step working of SYN, SYN-ACK, and ACK
In the first step, the client sends a SYN message to the server.
SYN means “synchronize”. This message says:
“We want to start a connection and here is my starting number.”
In the second step, the server replies with SYN-ACK.
This means:
“I received your request, I am ready, and here is my starting number.”
In the third step, the client sends an ACK message.
This message confirms:
“I received your response and the connection is now established.”
After this third step, both sides fully trust that the connection exists.
How data transfer works in TCP
Once the connection is established, real data transfer begins.
TCP does not send data as one big chunk. It breaks data into smaller pieces called segments. Each segment has a sequence number, which helps track the order.
When the receiver gets data, it sends back an acknowledgment (ACK). This acknowledgment tells the sender which data has been received successfully.
If the sender does not receive an acknowledgment within a certain time, it assumes the data was lost and sends it again.
This constant back and forth ensures safe delivery.
Sequence numbers and acknowledgements (high level idea)
Sequence numbers help TCP keep data in order.
Each piece of data has a number attached to it. The receiver uses these numbers to arrange data correctly, even if packets arrive out of order.
Acknowledgements tell the sender, “We have received data up to this point.”
This allows the sender to know exactly what was delivered and what needs retransmission.
We do not need to understand the math behind it at the beginning. The idea is enough.
How TCP handles packet loss and retransmission
Packet loss is normal on the internet. Networks are not perfect.
TCP constantly monitors acknowledgements. If an acknowledgment is missing, TCP assumes packet loss.
When this happens:
TCP resends the missing data
The receiver ignores duplicates
Data is reconstructed correctly
This happens automatically without the application knowing anything about it.
That is why TCP is called reliable.
How TCP ensures reliability, order, and correctness
TCP ensures reliability by using acknowledgements and retransmissions.
TCP ensures order by using sequence numbers.
TCP ensures correctness by verifying that data is complete and properly received before passing it to applications.
Because of this, applications like browsers and servers can focus on logic instead of worrying about broken data.
How a TCP connection is closed
Just like a connection must be created properly, it must also be closed properly.
TCP uses FIN and ACK messages to close a connection.
One side sends a FIN message saying, “I am done sending data.”
The other side acknowledges it.
Then the second side sends its own FIN.
Finally, the first side acknowledges that too.
This ensures both sides finish communication cleanly without data loss.
TCP connection lifecycle
A TCP connection goes through three main phases.
First, connection establishment using the 3 way handshake.
Second, data transfer using sequence numbers and acknowledgements.
Third, connection termination using FIN and ACK messages.
This full lifecycle makes TCP predictable and safe.




