Skip to main content

Command Palette

Search for a command to run...

TCP Working: 3-Way Handshake & Reliable Communication

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

What happens if we send data without rules?

Imagine shouting instructions across a crowded street.

Some words get lost.
Some arrive twice.
Some arrive out of order.
Some arrive when the other person wasn’t even listening yet.

That’s what raw data transfer looks like without rules. Computers are fast, and they need structure.

This is where TCP walks in like the boring but responsible adult.

What is TCP, and why is it needed?

TCP (Transmission Control Protocol) is a communication rulebook used on the Internet to send data reliably.

When you open a website, send a message, upload a file, or log in anywhere, TCP is usually working behind the scenes, making sure:

  • Data reaches the right place

  • Nothing important is lost

  • Everything arrives in the correct order

  • Both sides agree on what’s happening

Without TCP, the internet would feel like a glitchy group chat with a bad network.

Problems TCP is designed to solve

TCP exists because the Internet itself is unreliable.

It solves the problems like:

  • Packet loss - data can disappear mid-way

  • Out-of-order delivery - packets don’t always arrive in sequence

  • Duplicate packets - sometimes data gets sent twice

  • Unknown connection state - sender doesn’t know if receiver is ready

TCP doesn’t panic. It plans for all of this.

What is the TCP 3-Way Handshake?

Before any real data is sent, TCP makes sure both sides are ready.
This setup process is called the 3-Way Handshake.

Think of it like starting a phone call:

  1. “Can you hear me?”

  2. “Yes, I can hear you. Can you hear me?”

  3. “Yes, we’re connected.”

Only after this does the actual conversation start.

Step-by-step: SYN, SYN-ACK, ACK

SYN (Synchronise)

The client says:
“Hey server, I want to talk. Are you available?”

This message contains a sequence number, which is basically:
“This is where I’m starting from.”

SYN-ACK (Synchronise + Acknoledge)

The server replies:
“I hear you. I’m ready. And I got your starting number.”

The server also sends its own sequence number.
Now both sides know:

  • The order exists

  • The other is listening

  • Where counting should start

ACK (Acknowledge)

The client responds:
“Cool, I got your message too.”

Handshake complete. Connection established. Data can flow.

How data transfer looks in TCP

Once the connection is open, TCP starts sending data in chunks called segments.

Each segment includes:

  • Sequence number - where this piece fits

  • Acknowledgement number - what has been received so far.

The receiver keeps saying:
“I got data up to number X.”

This constant feedback loop keeps everything synchronised.

How TCP ensures reliability, order, and correctness

  1. Reliability

    If a packet goes missing, TCP notices.
    No acknowledgement? TCP resends it.

    Simple and effective.

  2. Order

    Packets can arrive in any order.
    TCP rearranges them using sequence numbers before handing data to the application.

    So your video doesn’t play sentence 5 before sentence 2.

  3. Correctness

    TCP checks for corrupted data.
    If something looks wrong, it gets reset.

    Your files arrive intact, not haunted.

How TCP handles packet loss

TCP assumes failure is normal.
If a packet isn’t acknowledged within a certain time:

  • It is retransmitted

  • Sending speed may be reduced

  • Network congestion is assumed, not ignored

TCP doesn’t rage. It adapts.

How TCP connection is closed

Ending a TCP connection is also polite. No ghosting.

FIN and ACK

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

  2. Other side sends ACK
    “Got it.”

  3. Other side sends its own FIN
    “I’m done too.”

  4. Final ACK
    “Connection closed.”

Everyone agrees. No loose ends.

Conclusion

TCP is not flashy. It doesn’t try to be cool.
It:

  • Establishes trust before talking

  • Keeps track of every message

  • Fixes mistakes silently

  • Ends conversations cleanly

That’s why the internet mostly works, even when everything else feels broken.

And yes, all of this happens every time you open a website.
In milliseconds. Without asking for applause.

Want more?

Blog: https://blogs.kanishk.codes/
Twitter: https://x.com/kanishk_fr/
LinkedIn: https://linkedin.com/in/kanishk-chandna/
Instagram: https://instagram.com/kanishk__fr/

More from this blog

Learn Tech With Kanishk

25 posts

Here, I share my learnings about tech, web development, generative AI, and whatever I am learning.