Skip to main content

Command Palette

Search for a command to run...

TCP Working: 3-Way Handshake & Reliable Communication

Published
2 min read

1. What is TCP and why is it needed?

TCP (Transmission Control Protocol) is a communication protocol used on the Internet to send data reliably from one device to another.

It is needed because the Internet itself is unreliable—data packets can get lost, duplicated, or arrive out of order. TCP makes sure that:

  • Data reaches the correct destination

  • Data arrives in order

  • Missing data is retransmitted

That’s why services like web browsing (HTTP/HTTPS), email, file transfer, etc., use TCP.

2. Problems TCP is designed to solve

TCP solves several key problems:

  • Packet loss – Data packets may get lost during transmission

  • Out-of-order delivery – Packets may arrive in the wrong order

  • Duplicate packets – Same packet may arrive more than once

  • Congestion – Network may become overloaded

  • Unreliable delivery – No guarantee data reaches the receiver

TCP handles all of these automatically.

3. What is the TCP 3-Way Handshake?

The 3-Way Handshake is the process TCP uses to establish a connection between a client and a server before data transfer begins.

It ensures that:

  • Both sides are ready to communicate

  • Sequence numbers are synchronized

  • The connection is reliable from the start

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

The handshake happens in three steps:

Step 1: SYN

  • Client sends a SYN (Synchronize) packet to the server

  • Meaning: “I want to start a connection”

Step 2: SYN-ACK

  • Server replies with SYN-ACK

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

Step 3: ACK

  • Client sends an ACK (Acknowledgment)

  • Meaning: “I received your response”

5. How data transfer works in TCP

Once the connection is established:

  • Data is broken into small segments

  • Each segment is given a sequence number

  • Receiver sends an ACK for received data

  • If an ACK is not received, the sender retransmits the data

6. How TCP ensures reliability, order, and correctness

TCP ensures:

Reliability

  • Uses ACKs and retransmission

  • Lost packets are resent

Order

  • Uses sequence numbers

  • Receiver rearranges packets correctly

Correctness

  • Uses checksum

  • Detects corrupted data and requests retransmission

7. How a TCP connection is closed

TCP connection termination is done using a 4-step process:

  1. One side sends FIN (finish)

  2. Other side sends ACK

  3. Other side sends FIN

  4. First side sends ACK