TCP Working: 3-Way Handshake & Reliable Communication

What Is TCP and Why Do We Need It?
Every time we open a website, download a file, or send an email, data travels across the internet. But the internet itself is unreliable. Data moves through many routers and networks, and there is always a chance that some part of the data may get lost, arrive late, or reach in the wrong order.
If data were sent without any rules, the result would be chaos. Webpages would load half-way, files would be corrupted, and messages would make no sense. To prevent this, the internet uses a protocol called TCP (Transmission Control Protocol).
TCP is needed because it ensures that data is delivered correctly, completely, and in the right order.
What Problems Does TCP Solve?
When data travels over the internet, several problems can occur naturally. Packets may be lost due to network congestion, arrive out of order because they take different paths, or get duplicated. Sometimes the receiver may not even be ready to accept data.
TCP is designed to solve all these issues. It makes sure that the sender and receiver are properly connected before data transfer starts. It also checks whether the data has reached successfully and fixes problems automatically when something goes wrong.
Without TCP, reliable communication on the internet would not be possible.
What Is the TCP 3-Way Handshake?
Before any data is sent, TCP first establishes a connection between the sender and the receiver. This connection setup process is called the TCP 3-Way Handshake.
The handshake ensures that both sides are ready to communicate and agree on basic communication parameters. Only after this process is complete does actual data transfer begin.
You can think of the 3-way handshake like starting a phone call. One person calls, the other answers, and then both confirm they can talk.
Understanding the 3-Way Handshake Using a Simple Analogy
Imagine two people, A and B, trying to talk.
Person A says, “Hello, can you hear me?”
Person B replies, “Yes, I can hear you. Can you hear me?”
Person A responds, “Yes, I can hear you too.”
Only after this exchange does the real conversation begin. TCP works in a very similar way.
Step-by-Step Working of SYN, SYN-ACK, and ACK
The first step of the handshake is SYN. The sender sends a message saying it wants to start a connection. This message also includes a starting sequence number that will help track data later.
The second step is SYN-ACK. The receiver responds by acknowledging the sender’s request and also sends its own request to synchronize.
The final step is ACK. The sender acknowledges the receiver’s response. At this point, both sides know that the other is ready, and the connection is established.
Once this process is complete, TCP allows data to flow.
How Data Transfer Works in TCP
After the connection is established, data is sent in small pieces called segments. Each segment is numbered using sequence numbers. These numbers help the receiver understand the correct order of data.
As the receiver gets the data, it sends back acknowledgements to tell the sender which data has been received successfully. This back-and-forth communication continues throughout the data transfer.
This system ensures that nothing is missed and everything is assembled correctly at the destination.
How TCP Ensures Reliability, Order, and Correctness
TCP ensures reliability by waiting for acknowledgements from the receiver. If an acknowledgement is not received within a certain time, TCP assumes the data was lost and sends it again.
Order is maintained using sequence numbers. Even if packets arrive in the wrong order, TCP rearranges them correctly before passing data to the application.
Correctness is ensured through error checking. If corrupted data is detected, TCP requests retransmission so that the correct data is delivered.
All of this happens automatically, without the user even noticing.
How TCP Handles Packet Loss and Retransmission
Packet loss is common on busy networks. TCP is designed to handle this smoothly. When the sender does not receive an acknowledgement for a specific sequence number, it resends only the missing data instead of starting over.
This selective retransmission saves bandwidth and ensures efficient communication while still maintaining reliability.
How a TCP Connection Is Closed
Once data transfer is complete, the TCP connection needs to be closed properly. This is done using FIN and ACK messages.
One side sends a FIN message to indicate that it has finished sending data. The other side acknowledges this and then sends its own FIN when it is done. The final acknowledgement confirms that both sides are ready to close the connection.
This graceful shutdown ensures that no data is accidentally lost at the end of communication




