TCP Three-Way Handshake Explained
- Networking Fundamentals & OSI Model
- TCP/IP Model
- Network Topologies
- IP Addressing & Subnetting
- Routing Algorithms & Protocols
- Switching Concepts
- Transport Layer Protocols (TCP & UDP)
- Application Layer Protocols
- Network Security & Firewalls
- Wireless Networking & Wi-Fi
- Network Address Translation (NAT)
- DNS Deep Dive
- Congestion Control & Flow Control
- Error Detection & Correction
- Network Devices
- VPN & Tunneling
- Load Balancing & CDN Networking
- Socket Programming
- Network Troubleshooting Tools
- Physical Layer & Transmission Media
- Data Link Layer & MAC Addressing
- Ethernet Protocol
- ARP (Address Resolution Protocol)
- ICMP Protocol
- Unicast, Multicast, Broadcast and Anycast
- Proxy Servers
- Port Numbers Reference
- Network Performance Metrics
- Quality of Service (QoS)
- Software-Defined Networking (SDN)
- HTTP/2 and HTTP/3 Overview
- 5G and Mobile Networks
- IoT Networking Basics
- VoIP Networking Basics
Why TCP Needs a Handshake Before Sending Data
TCP is a connection-oriented protocol - before any actual data is exchanged, both sides need to agree that a connection exists and synchronize their starting sequence numbers. This agreement happens through a three-step exchange.
The Three Steps
Client Server
|------- SYN ----------------->| "I want to connect, my sequence starts at X"
|<------ SYN-ACK ---------------| "Okay, and my sequence starts at Y"
|------- ACK ------------------>| "Confirmed, let's begin"
(connection now established - data can flow)What Each Flag Actually Means
| Step | Flag(s) | Purpose |
|---|---|---|
| 1 | SYN | Client requests a connection and proposes an initial sequence number |
| 2 | SYN-ACK | Server acknowledges the client's request and proposes its own sequence number |
| 3 | ACK | Client confirms the server's sequence number - connection is now open |
Why Both Sides Need Their Own Sequence Number
Sequence numbers let TCP track exactly which bytes have been sent and received, in what order, and detect any missing or duplicate data. Because data can flow in both directions simultaneously, each side needs its own independent sequence number - this is why the handshake exchanges two, not one.
Ending a Connection: A Similar, Longer Exchange
Closing a TCP connection uses a comparable exchange (often called a "four-way handshake," using FIN and ACK flags) since either side may still have data left to send even after deciding to close - the same careful, agreed-upon coordination that opens a connection also applies when ending one.