Skip to main content

Command Palette

Search for a command to run...

TCP Working: 3-Way Handshake & Reliable Communication

Published
3 min read
TCP Working: 3-Way Handshake & Reliable Communication

If the internet did not follow any rules, things would be very unpredictable.
Websites would load with missing content, broken layouts, and disordered data.

But whenever we open a website, everything looks properly arranged and smooth.
We never worry about data being missing or mixed up.

This smooth experience happens because the internet follows well-defined rules called protocols.

One of the most important protocols is TCP (Transmission Control Protocol).


Why Do We Need TCP?

When data travels from one computer to another over the internet, many problems can occur:

  • Data can be lost

  • Data can arrive in the wrong order

  • Data can get corrupted

  • Network can be slow or unstable

TCP is designed to solve all these problems.

It is a transport-layer protocol that ensures data reaches the receiver:

  • Completely

  • In correct order

  • Without corruption


What Is TCP (Transmission Control Protocol)?

TCP is a protocol that helps transfer data reliably from one computer to another.

Before sending data, TCP:

  • Establishes a connection between client and server

  • Divides data into small pieces

  • Tracks each piece

  • Resends missing data if required

Because of all these checks, TCP is slower, but very trustworthy.


How Data Transfer Works in TCP

When data is sent from one computer to another, TCP follows a proper flow:

  1. The data is broken into small chunks

  2. Each chunk is given a sequence number

  3. These sequence numbers help TCP track data order

  4. The receiver:

    • Confirms which chunks are received

    • Requests missing chunks again

  5. After receiving all chunks:

    • Data is arranged in correct order

    • Data is checked for corruption

This is how TCP ensures reliability and correctness.


TCP 3-Way Handshake (Connection Setup)

Before any data transfer begins, TCP creates a connection between client and server.

This connection happens in three steps, which is why it is called the 3-Way Handshake.

You can think of it like a simple conversation.

Step 1: SYN

The client sends a SYN message to the server.
It means:

“I want to talk to you.”

(SYN stands for synchronize)


Step 2: SYN-ACK

The server replies with SYN-ACK.
It means:

“I received your request, and I also want to talk.”


Step 3: ACK

The client responds with ACK.
It means:

“Okay, let’s start our conversation.”

After this step, the connection is successfully established.


How TCP Ensures Reliability During Data Transfer

While transferring data:

  • Each packet sent must be acknowledged

  • The receiver sends an ACK saying:

    “I have received this packet”

If a packet is missing:

  • TCP detects the missing sequence number

  • It asks the sender to retransmit that packet

TCP only sends the next data after confirming the previous one.
This is how TCP guarantees 100% accurate delivery.


How TCP Connection Is Closed

When data transfer is complete, the connection needs to be closed properly.

TCP closes the connection using FIN and ACK messages.

  1. One side sends FIN (I want to close the connection)

  2. The other side replies with ACK

  3. The second side sends its own FIN

  4. The first side replies with ACK

After this, the connection is fully terminated.


Why TCP Is Reliable but Slower

TCP takes time because it:

  • Creates a connection first

  • Tracks every packet

  • Confirms delivery

  • Handles retransmission

But this is exactly why TCP is used where accuracy matters.


Where TCP Is Commonly Used

  • Website loading

  • Emails

  • File downloads

  • Online payments

  • Login systems

Anywhere data loss is not acceptable, TCP is used.


Conclusion

TCP is the backbone of reliable internet communication.

It makes sure that:

  • Data reaches safely

  • Data arrives in correct order

  • No data is lost or corrupted

Because of TCP, we can browse websites, send emails, and transfer files without worrying about missing or broken data.