Skip to main content

Command Palette

Search for a command to run...

TCP Working: 3-Way Handshake & Reliable Communication

Published
5 min read
A

I’m Ashwin Gudepu, a web development learner currently part of the Chai Code cohort. I’m blind, so accessibility is not an afterthought for me. I write about coding, tools, and lessons from building usable web apps.

TCP Explained How the Internet Learns to Trust Data

Before a browser loads a website, before HTTP sends requests, and before data reaches your screen, something very important happens quietly in the background.

That something is TCP.

TCP is not visible. You never click it. You never configure it manually. But without it, the internet would feel broken, unreliable, and chaotic.

To understand TCP properly, it helps to start with the problem it was designed to solve.

What If Computers Sent Data Without Any Rules?

Imagine two people trying to communicate by sending letters, but without any agreement.

  • Pages arrive out of order

  • Some pages never arrive

  • Some pages arrive twice

  • Some pages are damaged

  • The receiver does not know when the sender is finished

If the message is short, this might be manageable. But for important communication, the whole exchange falls apart.

Early computer networks faced this exact situation. They could send data, but they could not trust what arrived.

This is the problem TCP was created to solve.

Why TCP Was Created

TCP was designed to answer one core question:

How can two computers communicate reliably over an unreliable network?

The network itself makes no promises. Data can be lost, delayed, duplicated, or arrive out of order.

TCP does not fix the network. Instead, it works around these problems and hides them from applications.

What TCP Actually Is

TCP stands for Transmission Control Protocol.

TCP is a set of rules that defines how two computers:

  • Start a communication

  • Send data safely

  • Detect missing or corrupted data

  • Resend lost data

  • End communication cleanly

TCP does not care what the data represents. It only cares that data arrives correctly and in order.

Why TCP Starts With a Handshake

Before sending real data, TCP requires agreement.

Both sides must confirm that:

  • They are reachable

  • They are ready to communicate

  • They agree on how data will be tracked

This agreement is created using the TCP three-way handshake.

The Three-Way Handshake as a Simple Conversation

Think of starting a serious phone call.

  1. You ask if the other person can hear you

  2. The other person confirms and asks the same

  3. You confirm and begin the conversation

TCP follows this exact idea.

Step 1: SYN – Request to Start Communication

The client sends a message with the SYN flag.

This means:

  • The client wants to start a connection

  • The client provides its initial sequence number

The sequence number is the reference point TCP uses to track all future data.

No actual application data is sent at this stage.

Step 2: SYN-ACK – Server Acknowledges and Responds

If the server is available, it responds with SYN-ACK.

This response confirms:

  • The server received the request

  • The server is ready to communicate

  • The server provides its own sequence number

Both sides now know where data tracking will begin.

Step 3: ACK – Connection Is Established

The client sends the final ACK.

This confirms the server’s sequence number and completes the handshake.

At this point, the TCP connection is officially established and data transfer can begin.

Why the Handshake Matters

The handshake prevents:

  • Old packets from previous connections being reused

  • Data being sent to an unresponsive server

  • Half-open connections

It is not a greeting. It is a safety agreement.

How Data Transfer Works in TCP

Once the connection is open, TCP begins transferring data.

Data is not sent as one large block. It is broken into smaller pieces called segments.

Sequence Numbers and Ordering

Each segment contains a sequence number.

This allows the receiver to:

  • Reassemble data in the correct order

  • Detect missing segments

  • Ignore duplicate data

Acknowledgements and Retransmission

After receiving data, the receiver sends acknowledgements (ACKs).

An ACK confirms which data has been received successfully.

If data is missing:

  • The sender notices missing acknowledgements

  • The missing data is retransmitted

This happens automatically and transparently.

How TCP Ensures Reliability and Correctness

TCP uses several mechanisms together:

  • Sequence numbers for order

  • Acknowledgements for confirmation

  • Retransmission for lost data

  • Checksums for error detection

  • Flow control to avoid overwhelming receivers

  • Congestion control to protect the network

Applications never see broken or incomplete data because TCP fixes problems first.

How a TCP Connection Is Closed

A TCP connection does not end suddenly.

Closing a connection also requires agreement.

The process uses FIN and ACK messages.

  1. One side sends FIN to indicate it is done sending data

  2. The other side acknowledges with ACK

  3. The second side sends its own FIN

  4. The final ACK confirms closure

This ensures all data is delivered and resources are released properly.

The Complete TCP Connection Lifecycle

Every TCP connection follows the same path:

  1. Connection establishment

  2. Data transfer

  3. Connection termination

Common Misunderstandings About TCP

  • TCP does not understand HTTP

  • TCP does not encrypt data

  • TCP does not know what a webpage is

  • TCP does not display or render content

TCP only ensures reliable delivery of bytes.

Why TCP Still Matters

TCP is still widely used for:

  • Web browsing

  • APIs

  • Email

  • File transfers

  • Secure communication

When correctness and reliability matter, TCP is chosen.

Final Thoughts

TCP is not flashy, but it is essential.

It turns an unreliable network into something applications can trust.

Once TCP is understood, delays, retries, and network behavior start making sense naturally.