TCPWeb DevelopmentwebdevCohort2026

TCP Explained: The "Handshake" That Makes the Internet Reliable

Understand TCP, the protocol ensuring reliable internet data transmission through a 3-way handshake, error correction, and orderly delivery methods

Kenil Patel
Kenil PatelFull Stack Engineer
TCP Explained: The "Handshake" That Makes the Internet Reliable

Imagine you are trying to send a 1000-piece puzzle to your friend via mail. You put all the pieces in separate envelopes and post them.

Without any rules, some envelopes might get lost, some might arrive out of order, and some might be damaged. Your friend would have a mess, not a puzzle!

On the internet, TCP (Transmission Control Protocol) is the set of rules that ensures your "puzzle pieces" (data packets) arrive safely, in the right order, and without any missing parts.


What is TCP and Why Do We Need It?

TCP is a connection-oriented protocol. This means before any data is shared, the two devices (like your phone and a server) must agree to talk to each other.

Problems TCP Solves:

  1. Lost Data: What if a packet disappears in the wires?

  2. Out-of-Order Data: What if piece #5 arrives before piece #1?

  3. Corruption: What if the data gets "glitched" during travel?

TCP handles all of this so that when you download a photo or an app, it's perfect every time.


The Famous 3-Way Handshake

Before TCP sends data, it performs a "3-Way Handshake." Think of it like a polite phone conversation:

Step 1: SYN (Synchronize)

Client: "Hey! I want to talk to you. Here is my starting sequence number (let's say 100)."

  • Technical term: The client sends a SYN packet.

Step 2: SYN-ACK (Synchronize-Acknowledge)

Server: "I hear you! I’m ready to talk too. I received your number 100, so I'm looking for 101 next. Also, here is my starting sequence number (let's say 500)."

  • Technical term: The server sends a SYN-ACK packet.

Step 3: ACK (Acknowledge)

Client: "Got it! I received your number 500, so I'm looking for 501 next. Let's start sending data!"

  • Technical term: The client sends an ACK packet.

Connection Established! Now the two devices trust each other.


How Data Transfer Works (The Reliable Way)

Once the handshake is done, the actual data transfer begins. TCP doesn't just "send and forget." It uses Sequence Numbers and Acknowledgements.

  1. Ordering: Every packet gets a number (1, 2, 3...). If the server receives packet #3 before #2, it knows to wait and re-order them correctly.

  2. Correctness: TCP checks the data for errors. If a packet is corrupted, it’s thrown away.

  3. Reliability (The "Did you get it?" rule):

    • Client sends Packet #1.

    • Server sends back an ACK (Acknowledgement) saying "I got #1, send #2."

    • If Packet #2 is lost: The client waits for a bit. If it doesn't get an ACK for #2, it simply retransmits (sends again) Packet #2.


How the Connection Closes (The Goodbye) ️

TCP is polite until the very end. It doesn't just hang up; it uses a 4-step process to close the connection using FIN (Finish) and ACK flags.

  1. Client: "I'm done sending data. (FIN)"

  2. Server: "Okay, I hear you. Let me finish my last tasks. (ACK)"

  3. Server: "Okay, I'm done too! (FIN)"

  4. Client: "Great. Goodbye! (ACK)"


Summary for Beginners

  • TCP is like a registered post service for the internet.

  • The 3-Way Handshake (SYN, SYN-ACK, ACK) starts the conversation.

  • Sequence Numbers keep things in order.

  • Retransmission fixes lost data.

  • FIN/ACK closes the connection gracefully.

You don't need to remember every packet header, but remembering that TCP = Reliability will make you a better developer!

No comments yet. Be the first to comment.