Skip to main content

Command Palette

Search for a command to run...

TCP Working: 3-Way Handshake & Reliable Communication

A beginner-friendly deep dive into the TCP protocol

Published
4 min read

TCP for Beginners: The Rules That Make the Internet Reliable

Imagine sending important information on the internet without any rules. Parts of your message might arrive late, out of order, duplicated, or not arrive at all because the network is not perfect. TCP exists to make communication reliable even when the network is messy.

What is TCP and why it is needed

TCP (Transmission Control Protocol) is a transport-layer protocol that provides a reliable, ordered way to send data between a client and a server. It is needed because real networks can lose packets, reorder them, or deliver duplicates, so TCP handles that so applications can communicate safely.
TCP sits on top of IP. It is the guardian in the room that ensures:

  • Reliability: No data is lost.

  • Ordering: Data arrives in the correct sequence.

  • Integrity: The data hasn't been corrupted.

Problems TCP is designed to solve

TCP is designed to solve practical internet problems, like:

  • Loss: some data never reaches the other side → TCP detects and retransmits.

  • Out-of-order delivery: pieces can arrive in the wrong sequence → TCP reorders using sequence numbers.

  • Duplicates: the same piece may arrive twice → TCP discards duplicates using sequence information.

  • No confirmation: sender needs to know what was received → TCP uses acknowledgements (ACKs).

These are the reasons TCP became the default safe delivery system for many internet apps.

What is the TCP 3-Way Handshake

Before TCP sends real data, it establishes a connection using the 3-way handshake. This handshake makes sure both sides are ready and synchronized. RFC 9293 describes the three-way handshake as the procedure to establish a connection.
Simple conversation analogy:

  • Client: Can we talk?

  • Server: Yes, I am ready. Are you ready too?

  • Client: Yes, I am ready.

Step-by-step working of SYN, SYN-ACK, and ACK

Let us walk through the handshake slowly:

Step 1: Client -> Server (SYN)

The client sends SYN to start the connection request.

Step 2: Server -> Client (SYN-ACK)

The server replies with SYN-ACK:

  • SYN = I am also ready to start

  • ACK = I received your SYN

Step 3: Client -> Server (ACK)

The client sends ACK to confirm the server’s response, and now the connection is established.

After this, both sides can start sending actual data.

How data transfer works in TCP

Once connected, TCP sends data and keeps track of it using two simple ideas:

Sequence numbers (high level)

TCP numbers the data so the receiver can rebuild it in correct order, even if it arrives mixed up. RFC 9293 explains TCP’s use of sequence numbers and acknowledgements as key concepts for reliable transfer.

Acknowledgements (ACKs)

The receiver sends back ACKs to tell the sender, I received data up to here. This allows the sender to know what arrived and what might need retransmission.

Imagine you are sending a book to a friend, but you can only mail one page at a time.

  • You number every page (1, 2, 3...).

  • When your friend gets Page 1, they text you: "Got Page 1, send Page 2."

The Feedback Loop

How TCP ensures reliability, order, and correctness

TCP ensures reliability mainly through:

A) Retransmission (handling packet loss)

If data is not acknowledged in time, TCP assumes it may be lost and re-sends it. TCP retransmission is commonly triggered by timeouts or repeated duplicate ACK signals.

B) Correct order (no jumbled data)

Even if packets arrive out of order, the receiver uses sequence information to reassemble the stream correctly.

C) Correctness (detecting errors)

TCP includes mechanisms (like checksums) so corrupted data can be treated as lost and resent, improving integrity.

How a TCP connection is closed

Closing a TCP connection is also a controlled process. TCP typically uses a FIN exchange, because each side closes its sending direction independently.

Beginner-friendly view:

  • One side says: I am done sending (FIN)

  • Other side replies: Okay, I got it (ACK)

  • Then the other side sends its own FIN when it’s done

  • Final ACK completes closure

Conclusion

TCP is the unsung hero of the internet. It takes an unreliable, chaotic network of cables and routers and creates a reliable pipe for our data.

  • The Handshake sets the rules.

  • Sequence Numbers keep the data in order.

  • ACKs confirm delivery.

  • Retransmission fixes the errors.

Understanding TCP is not just for network engineers. As a developer, knowing why a connection takes time to establish (latency) or why a download pauses (packet loss) gives you the power to build better, faster applications.