Skip to main content

Command Palette

Search for a command to run...

TCP Working: 3-Way Handshake & Reliable Communication

Published
4 min read

Imagine sending an important message over the internet with no rules at all.

You send data.
You don’t know if it arrived.
You don’t know if it arrived in order.
You don’t know if parts were lost.
You don’t even know if the other side is ready to listen.

That is exactly the problem TCP was designed to solve.

What Is TCP and Why Is It Needed?

TCP (Transmission Control Protocol) is a communication protocol used on the internet to ensure reliable, ordered, and error-checked data delivery between two systems.

When you:

  • Load a webpage

  • Log in to a website

  • Send an API request

  • Transfer a file

TCP is usually the protocol doing the heavy lifting underneath.

Without TCP, the internet would be fast but unreliable.

Problems TCP Is Designed to Solve

TCP exists because raw data transmission has serious problems:

  1. No guarantee data arrives

  2. No guarantee data arrives in order

  3. No way to detect missing pieces

  4. No confirmation that the receiver is ready

  5. No clean way to end communication

TCP introduces rules and structure to solve all of these.

What Is the TCP 3-Way Handshake?

Before any actual data is sent, TCP first establishes a connection using a process called the 3-Way Handshake.

Think of it as a short conversation before a real discussion begins.

The goal is simple:

Make sure both sides are ready and agree on how communication will happen.

now, let me explain TCP 3-way handshake using simple analogy :

The 3-Way Handshake ( Using Simple Analogy)

Let’s say a client wants to talk to a server.

Step 1: SYN : “Can we talk?”

The client sends a SYN (synchronize) message.

Meaning:

“I want to start a connection, and here’s my starting sequence number.”

At this point, no data is sent only intent.

Step 2: SYN-ACK : “Yes, and can you hear me?”

The server replies with SYN-ACK.

Meaning:

“I acknowledge your request, here’s my sequence number, and I’m ready.”

Now the server has confirmed:

  • It received the client’s request

  • It is ready to communicate

Step 3: ACK : “Confirmed. Let’s start.”

The client responds with ACK.

Meaning:

“I acknowledge your response. Connection established.”

After this step, both sides agree that:

  • The connection exists

  • Data transfer can safely begin

Why Three Steps Are Necessary

The handshake ensures:

  • Both sides are reachable

  • Both sides agree on initial sequence numbers

  • No half-open or fake connections exist

This prevents confusion, data corruption, and wasted resources.

How Data Transfer Works in TCP

Once the connection is established, data is sent in segments.

Each segment includes:

  • A sequence number

  • A portion of data

  • Control information

High-Level Idea

  • Data is broken into smaller pieces

  • Each piece is numbered

  • The receiver acknowledges what it receives

This allows TCP to track everything precisely.

Sequence Numbers and ACKs

Sequence Numbers

Sequence numbers tell TCP:

  • The order of data

  • What piece comes next

Acknowledgements (ACKs)

ACKs tell the sender:

“I received everything up to this point”

Together, they allow TCP to:

  • Detect missing data

  • Maintain correct order

  • Avoid duplication

You don’t need to know exact numbers yet just the concept.

How TCP Handles Packet Loss

If data is lost during transmission:

  1. The receiver notices a missing sequence number

  2. It does not acknowledge that missing data

  3. The sender waits for an ACK

  4. If no ACK arrives, the sender retransmits the data

This is how TCP ensures reliability, even on unstable networks.

How TCP Ensures Reliability, Order, and Correctness

TCP guarantees:

  • Reliability → Lost data is retransmitted

  • Order → Data is reassembled correctly

  • Correctness → Corrupted data is detected and resent

  • Flow control → Sender doesn’t overwhelm the receiver

This is why TCP is trusted for critical operations like logins, payments, and file transfers.

How a TCP Connection Is Closed

Just like starting a connection requires rules, ending it cleanly does too.

TCP uses FIN and ACK messages to terminate a connection.

Simple View

  1. One side sends FIN → “I’m done sending data”

  2. Other side sends ACK → “I acknowledge”

  3. Other side sends FIN

  4. First side sends ACK

Only after both sides agree does the connection fully close.

This ensures:

  • No data is lost at the end

  • Resources are released properly

Why TCP Matters

TCP may feel invisible, but it is one of the most important protocols on the internet.

It allows:

  • Browsers to trust servers

  • Servers to trust clients

  • Applications to work reliably at scale

Higher-level technologies like HTTP, APIs, and databases depend on TCP behaving correctly underneath.