TCP Working: 3-Way Handshake & Reliable Communication
The internet works because devices can communicate reliably across complex and unpredictable networks. One of the most important protocols that makes this possible is TCP (Transmission Control Protocol). Whether you are browsing websites, sending emails, or streaming data, TCP is quietly ensuring that your information reaches its destination correctly.
In this blog, we will see how TCP works, especially the working of 3-Way Handshake, and how it guarantees reliable communication.
What is TCP and Why It Is Needed
TCP (Transmission Control Protocol) is a connection-oriented transport layer protocol used to transmit data between devices over a network.
It operates at the Transport Layer (Layer 4) of the OSI model and works together with IP (Internet Protocol).
Why Do We Need TCP?
The internet is an unreliable medium, because:
Packets can be lost
Packets can arrive out of order
Packets can be duplicated
Data can get corrupted
TCP is needed because it ensures reliable communication, guarantees data arrives in order, checks for errors, and controls data flow and congestion. Without TCP, applications like web browsing, online banking, and file transfers would be unreliable.
Problems TCP Is Designed to Solve
TCP was designed to handle several real-world networking problems:
1. Packet Loss
Networks can drop packets due to congestion or errors. TCP detects and retransmits lost packets.
2. Out-of-Order Delivery
Packets may take different paths and arrive in the wrong order. TCP reorders them correctly.
3. Data Corruption
Data may get corrupted during transmission. TCP detects corruption using checksums.
4. Network Congestion
Too much traffic can overload the network. TCP reduces transmission speed when congestion is detected.
5. Flow Control
A fast sender can overwhelm a slow receiver. TCP ensures the sender transmits only as much as the receiver can handle.
What Is the TCP 3-Way Handshake?
Before two devices start sending data, TCP establishes a connection using a process called the 3-Way Handshake.
This ensures:
Both sides are ready
Initial sequence numbers are synchronized
Communication parameters are agreed upon
The handshake involves three steps:
SYN
SYN-ACK
ACK
Step-by-Step Working of SYN, SYN-ACK, and ACK
Let’s assume a client wants to connect to a server.
Step 1: SYN (Synchronize)
- The client sends a TCP segment with SYN flag set and and Initial Sequence Number (ISN). This means: "I want to start communication, and here is my starting sequence number."
Step 2: SYN-ACK (Synchronize + Acknowledge)
The server responds with:
SYN flag set
ACK flag set
Its own sequence number
Acknowledgment number = client’s ISN + 1
This means: "I received your request. Here is my sequence number, and I acknowledge yours."
Step 3: ACK (Acknowledge)
- The client sends ACK flag set and an Acknowledgment number = server’s ISN + 1. This means "I received your sequence number. Connection established."
Now the connection is fully established, and data transfer can begin.
How Data Transfer Works in TCP
Once the connection is established the data Is broken into segments where large data is divided into smaller TCP segments. Each segment has:
Sequence number
Acknowledgment number
Checksum
Window size
Flags
TCP then uses a sliding window protocol to control how much data can be sent before waiting for acknowledgment. The receiver advertises a window size. The sender sends data within that window. As ACKs are received, the window slides forward.
This allows efficient and continuous data transmission.
How TCP Ensures Reliability, Order, and Correctness
TCP is considered reliable because of several built-in mechanisms:
1. Sequence Numbers
Each byte of data has a sequence number. This helps to detect missing data and also reassemble data in order.
2. Acknowledgments (ACKs)
The receiver sends ACKs to confirm received data. If the sender does not receive an ACK within a certain time, it retransmits the data.
3. Retransmission Mechanism
If a packet is lost, an ACK is not received or duplicate ACKs are received -> TCP automatically retransmits missing segments.
4. Checksum (Error Detection)
Each segment includes a checksum. If corrupted data is detected, the receiver discards it and hence the sender retransmits.
5. Flow Control
TCP has mechanisms which prevents sender from overwhelming receiver
6. Congestion Control
TCP adjusts its sending rate using algorithms like:
Slow Start
Congestion Avoidance
Fast Retransmit
Fast Recovery
This ensures network stability.
How a TCP Connection Is Closed
Closing a TCP connection typically involves four steps:
Step 1: The client sends a FIN flag-> "I have finished sending data."
Step 2: The server sends ACK-> "I acknowledge your FIN."
Step 3: The server sends its own FIN-> "I am also finished."
Step 4: ACK -> The client sends final ACK.
Step 5: After this:
The connection is closed.
The client enters a TIME_WAIT state briefly to ensure all packets are properly handled.
Conclusion
TCP is one of the most critical protocols in networking. It ensures:
Reliable delivery
Ordered communication
Error detection
Flow control
Congestion management
The 3-Way Handshake establishes a safe and synchronized connection, while TCP’s mechanisms guarantee that data is delivered correctly and efficiently.
Without TCP, the modern internet which includes secure browsing, file transfers, online services would not have functioned reliably as we experience them today.

