Fundamentals 6 min read

Understanding TCP: Why Three-Way Handshake and Four-Way Teardown Matter

This article explains the TCP three-way handshake and four-way termination processes, detailing each packet exchange, state transition, and the reasons why these mechanisms are essential for reliable network communication.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Understanding TCP: Why Three-Way Handshake and Four-Way Teardown Matter

TCP is a core protocol for reliable data transmission; this article summarizes its connection establishment and termination processes.

TCP handshake diagram
TCP handshake diagram

First, the three-way handshake:

1. The client initiates the connection by sending a SYN=1, ACK=0 packet with an initial sequence number seq=x.

SYN creates a synchronization number; when SYN=1 and ACK=0, it signals a connection request. The SYN packet cannot carry data but consumes a sequence number.

ACK is meaningful only when ACK=1, confirming the expected next byte. After the handshake, all packets have ACK=1.

The client’s state becomes SYN‑SEND.

2. The server receives the SYN packet and replies with SYN=1, ACK=1, acknowledging seq=x+1 and choosing its own initial sequence number seq=y.

The server’s state becomes SYN‑RECEIVED.

3. The client receives the server’s response and sends a final ACK=1 with ack=y+1.

The client’s state transitions to ESTABLISHED, completing the three-way handshake.

The article also explains why a two‑step handshake is insufficient, illustrating scenarios where lost or duplicate packets could cause resource waste or erroneous connections.

Then, the four-way termination:

Both sides are in ESTABLISHED state.

1. The client initiates termination by sending FIN=1, seq=u (u is the last byte sent plus one). The client enters FIN‑WAIT‑1, awaiting the server’s acknowledgment.

2. The server acknowledges with ACK=1, seq=v, ack=u+1, entering CLOSE‑WAIT.

3. When the server has no more data to send, it sends FIN=1, ACK=1, ack=u+1, seq=w, entering LAST‑ACK.

4. The client acknowledges with ACK=1, seq=u+1, ack=w+1, then waits for two time‑wait intervals before fully closing.

The waiting period ensures that any lost ACKs are retransmitted and that delayed packets from the previous connection do not interfere with future connections.

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 fundamentalsConnection termination
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.