Skip to main content

Command Palette

Search for a command to run...

TCP Working: 3-Way Handshake & Reliable Communication (Beginner’s Guide)

Updated
4 min read

The internet doesn’t magically move data from one computer to another. If it did, messages would arrive out of order, partially, or not at all. To prevent chaos, the internet relies on rules—and one of the most important rule sets is TCP (Transmission Control Protocol).

In this article, you’ll learn how TCP works, why it exists, how the 3-way handshake establishes a connection, and how TCP ensures reliable, ordered, and correct communication—all explained in a beginner-friendly way.


What Is TCP and Why Is It Needed?

TCP is a transport-layer protocol that ensures data sent over the internet arrives:

  • Completely

  • In the correct order

  • Without duplication

Whenever you:

  • Load a website

  • Send an email

  • Download a file

TCP is working behind the scenes.

Without TCP, the internet would feel unreliable and broken.


What Happens If Data Is Sent Without Rules?

Imagine sending a long message without any rules:

  • Parts of the message arrive late

  • Some parts never arrive

  • Parts arrive in the wrong order

  • The receiver doesn’t know what’s missing

This is exactly what would happen if data were sent freely with no control system.

TCP exists to solve these problems.


Problems TCP Is Designed to Solve

TCP was created to handle real-world network issues such as:

  • Packet loss – data disappears on the way

  • Out-of-order delivery – data arrives scrambled

  • Duplicate packets – the same data arrives twice

  • Unreliable connections – temporary network failures

TCP doesn’t just send data—it manages communication.


What Is the TCP 3-Way Handshake?

Before any data is sent, TCP must establish a connection between two devices. This process is called the 3-Way Handshake.

Think of it like starting a conversation politely instead of shouting information randomly.

Conversation Analogy 🗣️

  1. “Can you hear me?”

  2. “Yes, I can hear you.”

  3. “Great, let’s talk.”

Only after this does real communication begin.


Step-by-Step: SYN, SYN-ACK, and ACK

Let’s walk through the handshake slowly and clearly.

Step 1: SYN (Synchronize)

  • The client sends a SYN message

  • Meaning: “I want to start a connection.”

Step 2: SYN-ACK

  • The server responds with SYN-ACK

  • Meaning: “I received your request and I’m ready.”

Step 3: ACK (Acknowledgment)

  • The client sends ACK

  • Meaning: “Great, connection confirmed.”

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


How Data Transfer Works in TCP

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

Each segment includes:

  • A sequence number (its position)

  • An acknowledgment number (what was received)

  • Error-checking information

This allows TCP to track what was sent and what arrived.


How TCP Ensures Reliability, Order, and Correctness

TCP guarantees reliable communication using several techniques.

1. Sequence Numbers

Each piece of data is numbered so the receiver knows:

  • The correct order

  • If something is missing

2. Acknowledgments (ACKs)

The receiver sends back ACKs saying:

  • “I received everything up to this point.”

3. Retransmission

If an ACK is not received:

  • TCP assumes data was lost

  • The missing data is resent

4. Error Checking

TCP checks for corrupted data and discards anything incorrect.

Courier analogy:
TCP is like a courier who:

  • Numbers every package

  • Requires delivery confirmation

  • Re-sends lost packages


How TCP Handles Packet Loss

Packet loss is normal on networks. TCP reacts calmly:

  1. Data is sent

  2. ACK is expected

  3. ACK doesn’t arrive

  4. TCP waits briefly

  5. Missing data is resent

This happens automatically and invisibly to users.


How a TCP Connection Is Closed

When communication is finished, TCP does not just stop. It performs a graceful shutdown to ensure no data is lost.

Connection Termination Using FIN and ACK

  1. One side sends FIN (finished sending data)

  2. The other side sends ACK

  3. The second side sends its own FIN

  4. Final ACK is sent

Only then is the connection fully closed.


TCP Connection Lifecycle (Big Picture)

Here’s the full journey of a TCP connection:

  1. Establish connection (3-way handshake)

  2. Transfer data reliably

  3. Handle loss and retransmission

  4. Close connection gracefully

This lifecycle is why TCP is trusted for important communication.


Conclusion

TCP exists because the internet is unreliable by nature. Through:

  • The 3-way handshake

  • Sequence numbers and acknowledgments

  • Retransmission and graceful shutdown

TCP turns an unreliable network into a trustworthy communication system.

Once you understand TCP’s working, the behavior of many internet technologies suddenly makes sense. You don’t need to memorize packet formats—just remember TCP is careful, structured, and reliable.

3 views