NETLEARN
Lesson 02Transport

Closing a TCP Connection

Every connection has a lifetime. When there is no more data to send, both ends say goodbye with a FIN/ACK wave: four steps, not three.

Layer
Layer 4 · Transport
Reference
RFC 9293
Steps
4
Clientbrowser
Serverweb server
legendrequestresponsecontrolmessage in flight

Common misunderstandings

  • A connection that isn't closed cleanly leaves TIME_WAIT behind. A busy server can run out of ephemeral ports.

Key notes

4 steps, not 3
Teardown isn't symmetric with setup: each direction needs its own FIN+ACK.
Half-close
One side can finish first while the other is still sending.
TIME_WAIT
The client waits 2×MSL so stray packets don't arrive on a new connection.
If you're in a hurry
RST cuts the connection instantly with no farewell handshake. That makes other connections complain.