# TCP Working: 3-Way Handshake & Reliable Communication

Hey Everyone,

> Have you ever stopped on this how your message is sent to your friend living in a far country in order without messing any data?
> 
> Answer: TCP

Let’s break it down step by step — no jargon overload, just simple.

### Why Do We Even Need Rules to Send Data?

Imagine sending a very long message to your friend by pieces of paper in the air.

Some pieces might:

* Get lost
    
* Arrive late
    
* Arrive out of order
    
* Reach the wrong person
    

That’s exactly what happens on the internet **without rules**.

So we need a system that ensures:

* Data reaches the right place
    
* Nothing is lost
    
* Everything arrives in the correct order.
    

That system is **TCP**.

## What Is TCP?

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769716203309/f4d04c6f-4426-4e3f-b9e9-d366f5e3ecf1.png align="center")

**TCP (Transmission Control Protocol)** is a <mark>transport-layer</mark> protocol that provides:

* Reliablity
    
* Mantain order of the packets
    
* Error Checking
    
* Guarantee Delivery
    

### What Is the TCP 3-Way Handshake?

TCP does **not** send data immediately.

First, it establishes a connection using something called the **<mark>3-Way Handshake.</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769716649046/eaa64f82-d502-4259-9474-1ac1428c5972.png align="center")

The **3-Way Handshake** is TCP’s way of saying:

> “Are you ready to talk?”  
> “Yes, I’m ready.”  
> “Cool, let’s start.”

It ensures **both sides are ready** before data transfer begins.

### Step-by-Step: TCP 3-Way Handshake

Let’s say **Client wants to talk to Server**.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769717122752/c9810607-3d0e-4ed4-8caf-92f3f0e95e10.png align="center")

### Step 1: SYN (Client → Server)

It is like the client is asking the server

> A Server are you ready. I want to create a connection

### Step 2:SYN ACK(Server→Client)

The server responds to the request

> Yes i got your request. I am ready

### Step 3:ACK(Client)

The client sends an **ACK**.

Meaning:

> Acknowledged. Let’s Proceed with the connection.

🎉 **Connection established!**

Now, both sides trust each other and data transfer can begin.

### How Data Transfer Works in TCP

Once connected, TCP sends data in segments.

Each segment has:

* Sequence number
    
* Data
    
* Error-checking info
    

### What Happens When Data Is Sent?

1. Client sends data with a sequence number
    
2. Server receives it
    
3. Server sends an ACK
    
4. Client sends the next chunk
    

This continues until all data is delivered.

### How TCP ensures reliability, order, and correctness

* TCP ensures reliability by waiting for an acknowledgment signal indicating that the packet is successfully transferred.
    
* Even if packets arrive out of order, TCP reassembles them correctly
    
* If data gets corrupted, TCP detects it and requests retransmission
    

No ACK?  
👉 TCP assumes data is lost.

### What If a Packet Is Lost?

Suppose 3 packets are going

* 1 packet transferred ✅
    
* 2nd packet fail ❌
    
* 3rd packet successfully transferred ✅
    

TCP will know that, so it will again send the 2nd packet.

This is why TCP is reliable but slower than UDP.

### How a TCP Connection Is Closed

When communication is done, TCP closes the connection gracefully.

### Connection Termination (FIN & ACK)

1. Client sends **FIN** → “I’m done.”
    
2. Server sends **ACK**
    
3. Server sends **FIN**
    
4. Client sends **ACK**
    

Connection closed safely

No half-open or broken connections.

## TCP Connection Lifecycle

1. Establish → 3-Way Handshake
    
2. Transfer → Reliable data exchange
    
3. Close → FIN & ACK
    

### Where TCP Is Used in Real Life

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769718022465/5aea926f-a096-4f1c-be7c-b44945814c92.png align="center")

* File Transfer
    
* Messaging
    
* YouTube Live Streaming 😮
    

> Youtube Streaming How? In your earlier blogs you told that for live streaming UDP is used over TCP.
> 
> Yes Yes, I know but Youtube live uses TCP as if someone wants to go back 10-20sec.
> 
> But how can it handle speed?
> 
> Youtube gives a 40 second delay in live streaming that why it works fine with TCP.

---

And now, you know What is 3 way handshake in TCP.

If you have any doubt or want to connect, feel free to drop a comment — I’d be happy to help.

Thanks for reading, and see you in the next blog!

Peace ✌️ and Happy Learning!
