TCP Working: 3-Way Handshake & Reliable Communication
The Problem: Unreliable Data Transfer
Without rules, data sent over networks would be chaotic:
Packets could arrive out of order
Data could be corrupted
Packets might get lost
No way to know if the recipient is ready
TCP solves these problems by providing reliable, ordered, and error-checked data delivery.
TCP 3-Way Handshake: Establishing a Connection
Before data transfer, TCP establishes a connection using a three-step process:
Step-by-Step Breakdown:
SYN (Synchronize)
Client sends: "I want to connect. My starting sequence number is 100."
Contains: SYN flag set, Initial Sequence Number (ISN=100)
SYN-ACK (Synchronize-Acknowledge)
Server responds: "I acknowledge your request (101). I accept. My starting number is 300."
Contains: SYN and ACK flags set, Acknowledgment Number=101, ISN=300
ACK (Acknowledge)
Client confirms: "I acknowledge your sequence number (301). Let's start."
Contains: ACK flag set, Acknowledgment Number=301
Sequence numbers track data bytes sent. Acknowledgments confirm received bytes (ACK number = next expected byte).
Data Transfer with Reliability
During data transfer, TCP ensures reliability through:
Sequencing: Each byte gets a number
Acknowledgments: Receiver confirms received data
Retransmission: Unacknowledged data is resent
Flow Control: Prevents overwhelming the receiver
Error Checking: Checksums detect corruption
Example Data Transfer:
Client: "Here's bytes 101-200" (seq=101)
Server: "Got them, send byte 201 next" (ack=201)
Client: "Here's bytes 201-300" (seq=201)
If Server doesn't acknowledge within timeout, Client retransmits bytes 201-300.
Connection Termination: Graceful Close
TCP connections close cleanly using a four-step process:
FIN from one side: "I'm done sending"
ACK from other side: "I acknowledge your FIN"
FIN from other side: "I'm also done sending"
ACK from first side: "I acknowledge your FIN"
Both sides confirm they've received all data before closing.
TCP vs. Raw Data Transfer
Without TCP:
No guarantee of delivery
No order preservation
No error detection
No flow control
With TCP:
All data arrives intact and in order
Lost packets are automatically retransmitted
Corruption is detected and fixed
Sender adapts to receiver's capacity
Why This Matters
Every web page, email, and file transfer uses TCP. When you load this page:
Browser establishes TCP connection to server (3-way handshake)
HTTP request sent over TCP (reliably delivered)
Web page data transferred in ordered chunks
Connection closes when complete
TCP's reliability makes the Internet work predictably. Without it, we would constantly worry about data loss and corruption in everyday web browsing, file downloads, and communications.
Enjoyed reading this blog? Let's connect!
🐦 Twitter/X: @rohan_gupta96
💼 LinkedIn: https://www.linkedin.com/in/rohangupta9896
🐙 GitHub: https://github.com/rohan9896