Fundamentals 7 min read

Why Does TCP Require a Three‑Way Handshake and a Four‑Way Teardown?

This article explains how TCP guarantees reliable transmission through a three‑way handshake for connection establishment and a four‑step termination process, detailing each packet’s flags, sequence numbers, and the reasons why these multi‑step procedures are essential for robust network communication.

Open Source Linux
Open Source Linux
Open Source Linux
Why Does TCP Require a Three‑Way Handshake and a Four‑Way Teardown?

Three‑Way Handshake

TCP ensures reliable data transfer by establishing a connection through three sequential steps.

First Handshake

The client sends a SYN segment (SYN=1, ACK=0, seq=x) to the server and enters the SYN‑SENT state.

SYN=1, ACK=0 indicates a connection request.

x is the initial sequence number; a SYN segment consumes one sequence number.

Second Handshake

Upon receiving the request, the server replies with SYN=1, ACK=1, seq=y, ack=x+1 and moves to the SYN‑RCVD state.

SYN=1, ACK=1 marks the server’s acceptance.

y is the server’s initial sequence number.

ack=x+1 tells the client the next expected byte.

Third Handshake

The client acknowledges the server’s response with ACK=1, seq=x+1, ack=y+1, entering ESTABLISHED; the server also moves to ESTABLISHED, completing the connection.

Why Three Handshakes?

The extra step prevents stale connection requests from being mistakenly accepted, which could waste server resources if a client’s request is lost and later arrives after the client has timed out.

Four‑Way Teardown

Closing a TCP connection requires four steps, reflecting its bidirectional nature.

First Teardown

Side A, having finished sending data, sends a FIN=1, seq=u segment and enters FIN‑WAIT‑1.

FIN=1 signals a release request.

seq=u (u‑1 is the last byte sent).

Second Teardown

Side B acknowledges with ACK=1, seq=v, ack=u+1, entering CLOSE‑WAIT, then sends its own FIN=1, seq=v, ack=u+1.

ACK=1 confirms receipt.

v‑1 is B’s last byte.

ack=u+1 expects the next byte from A.

Third Teardown

After sending all data, B sends FIN=1, ACK=1, seq=w, ack=u+1 and moves to LAST‑ACK.

Fourth Teardown

A acknowledges with ACK=1, enters TIME‑WAIT for 2 MSL to ensure B receives the final ACK; after this period, A closes, and B follows suit, releasing both TCBs.

Why TIME‑WAIT?

TIME‑WAIT guarantees that B can retransmit its final FIN if the ACK is lost; without this wait, B might never close properly.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

TCPThree-way handshakenetwork fundamentalsFour-way terminationreliable transmission
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.