From Connection to Delivery : TCP's 3-Way Handshake and Reliability

Introduction
In day to day life, we all constantly use chat applications to communicate with our family and friends, stream videos on online platforms, and attend virtual meetings for professional work. These things have become so seamless that we rarely think about the inner workings behind all these services. It’s natural to wonder how the correct message reaches the correct person, how videos play smoothly without any interruptions, or how voice and video remains stable over long distances.
All of these services rely heavily on the underlying networking technologies that ensure data is transferred accurately and reliably over the network. One of the most important of these technologies is Transmission Control Protocol, or more commonly known as TCP.
What is TCP?
By text book definition, TCP or Transmission Control Protocol is connection-oriented and reliable protocol that works on transport layer in both OSI model and TCP/IP model. This ensures that data is delivered accurately, in-order and without any loss.
Now let’s understand that in more details. In the above paragraph, I highlighted one very important thing, connection-oriented. Many of you may get confused about what kind of connection I’m talking about.
The connection established by TCP is not a physical connection like a dedicated cable or wire between two system. Instead, it is a logical end-to-end connection created at transport layer between two communicating applications. We’ll have a deep dive on how the communication is established later.
Now, we have enough context to discuss the problems that TCP is designed to solve.
Problems that TCP is designed to solve
In every field we can think of, nothing significant is created out of fun. People face real life problems and develop solutions to tackle them. Before TCP was introduced, data communication over networks brought several problems
Packet Loss - When data travels over a network, it is broken into small packets and sent through different paths. Now, the packets may get dropped due to network congestion, faulty links or buffer overflow in router. Without a mechanism to detect the packet loss, the data will be incomplete.
TCP solves this problem using acknowledgement (ACK) and re-transmission. An acknowledgement is sent from receiver to sender to inform that a packet is successfully received and it can now receive the next packet.
Out-of-Order delivery - When a sender sends data packets, the packets may arrive in different order than they were sent because then can take different routes through the network. This leads to data corruption.
TCP solves this by assigning sequence numbers to each packet. This allows the receiver to rearrange the packets correctly.
Sender Overwhelming the Receiver - A fast sender may send data faster than the receiver can process it, causing buffer overflow.
TCP solves this though flow control, using a sliding window mechanism, where the receiver advertises how much data it can handle.
I’m providing a example of how 3-Way Handshake looks using wireshark.

What is the TCP 3-Way Handshake?
Previously I mentioned a logical end-to-end connection between the sender and receiver. Now we have enough context to have a deep dive on it. The connection is established through a process called 3-Way Handshake. It is 3 way because it goes through 3 steps -
Step 1: SYN - This step is called Synchronization where the connection is initiated. The sender sends a segment with a flag called SYN along with the initial sequence number.
Step 2: SYN+ACK - Upon receiving the SYN segment with the initial sequence number, the receiver responds with a SYN flag with its own sequence number and a Acknowledgement flag called ACK with the acknowledgement number which is Sender Sequence Number+1. This step basically acknowledges that the receiver has received the sender’s segment and forwards its segment.
Step 3: ACK - Upon receiving the segment from the receiver, the sender sends back an ACK to acknowledge that the sender has also received the response from the receiver. Again the ACK number is Receiver Sequence Number+1.
After these 3 steps, the connection is now established between the sender and receiver.
How data transfer works in TCP?
Once the 3-Way Handshake is completed and the connection is established, TCP begins data transfer between the two applications. Initially the application sends a stream of data to TCP. TCP breaks it into smaller segments. Each segment is assigned a sequence number.
TCP sends these segments over the network. Multiple segments can be sent without waiting for immediate acknowledgements, depending on the window size.
Finally the receiver checks each segment for errors using a checksum. If the segment is correct, the receiver sends an ACK. If a segment is lost or corrupted, the receiver does not acknowledge it. The sender waits for a timeout then re-transmits the missing segment. This way TCP maintains correctness of the data.
If segments arrive out of order, TCP buffers them, means stores them in a temporary location. Data is delivered to the application only in correct order. This way TCP handles order.
How a TCP connection is closed?
After sending the data, now TCP needs to close the connection between the sender and the receiver to end the process. It is handled by using another 3 step process -
Step 1: FIN – Sender sends a segment with the FIN flag set to 1, which indicates that it has finished sending data and wants to terminate the connection.
Step 2: ACK – The receiver responds by sending an acknowledgment (ACK) for the received FIN segment, confirming that it has received the termination request. At this stage, the sender cannot send any more data, but the receiver can still transmit remaining data if any.
Step 3: FIN + ACK – After the receiver finishes sending its remaining data, it sends a segment with the FIN flag set. The sender then replies with an ACK, and the connection is completely closed from both sides.
This process ensures that the TCP connection is closed gracefully, allowing both the sender and receiver to finish their communication properly before terminating the connection.
Conclusion
Transmission Control Protocol (TCP) plays a critical role in making modern network communication reliable and efficient. From establishing a logical connection using the 3-Way Handshake, to ensuring accurate and in-order data delivery, and finally closing the connection gracefully, TCP carefully manages every stage of communication between two applications.
By handling challenges such as packet loss, out-of-order delivery, and flow control, TCP abstracts the complexities of unreliable networks and provides applications with a dependable communication channel. This is why services like web browsing, file transfers, video streaming, and online communication can function smoothly even over complex and unpredictable networks.
Understanding how TCP works not only helps in building better network-aware applications but also provides deeper insight into the invisible mechanisms that power the internet we use every day.



