Skip to main content
CSNetworkingDiagramBeginner

3-Way Handshake

KO: 3-Way 핸드셰이크·EN: 3-Way Handshake·JA: 3ウェイハンドシェイク

The three-step SYN, SYN-ACK, ACK exchange establishing a reliable TCP connection by synchronizing initial sequence numbers in both directions

Table of Contents

Structure Diagram

TCP 3-Way Handshake Connection Establishment (1 RTT)
Client State3 steps
Server State3 steps
STEP 11. Send SYN(25ms)
Quick Answer

What is 3-Way Handshake?

The three-step SYN, SYN-ACK, ACK exchange establishing a reliable TCP connection by synchronizing initial sequence numbers in both directions. It is a core concept in Networking within CS.

Core Principles

The TCP 3-Way Handshake verifies bidirectional reachability and synchronizes Initial Sequence Numbers (ISN) before payload transfer begins.

  1. SYN: Client sends random seq = x (SYN_SENT).
  2. SYN-ACK: Server replies with ack = x + 1 and its own seq = y (SYN_RCVD).
  3. ACK: Client acknowledges y + 1, entering ESTABLISHED.

Three messages are required so both sides confirm the other can both send and receive.

Practical Takeaways

  • Eliminate repeated 1-RTT overhead: Use HTTP Keep-Alive and DB connection pooling to amortize handshake latency over many requests.
  • Defend against SYN Floods: Attackers exhaust the server's half-open SYN backlog by withholding final ACKs; enable kernel SYN Cookies to stay stateless under attack.
  • Mind TIME_WAIT on teardown: Graceful closes use a 4-way FIN/ACK handshake leaving the active closer in TIME_WAIT to drain delayed packets.

Notable Examples

  • HTTP/1.1, HTTP/2, SSH, PostgreSQL: Every TCP session opens with a 3-way handshake.
  • TCP Fast Open & QUIC: Modern optimizations eliminating separate handshake round trips.