Skip to main content

TCP connection establishment and release

Short answer

Connection establishment uses a three-way handshake: client sends SYN, server replies SYN+ACK, client sends ACK. Release is four-way: each side independently sends FIN and receives ACK, with the final endpoint in TIME_WAIT (2×MSL) to discard old segments and retransmit lost ACKs.

How is a connection established and released in TCP?

TCP is connection-oriented, so a connection is opened with a three-way handshake and closed with a four-step exchange.

Connection establishment (three-way handshake)

  Client                         Server
    |-------- SYN, seq=x -------->|   (server in LISTEN)
    |<--- SYN+ACK, seq=y, ack=x+1-|
    |-------- ACK, ack=y+1 ------>|
    |        ESTABLISHED          |
  1. Client sends SYN with its initial sequence number x.
  2. Server replies SYN+ACK with its own number y and acknowledges x+1.
  3. Client sends ACK y+1. Data transfer can begin.

Connection release (four-way)

  Client                         Server
    |------------ FIN ----------->|
    |<----------- ACK ------------|  (client -> server closed)
    |<----------- FIN ------------|
    |------------ ACK ----------->|
    | TIME_WAIT (2 x MSL), closed |

Each direction is closed independently by a FIN and acknowledged by an ACK. After the last ACK the client waits 2 × MSL in TIME_WAIT so a lost ACK can be resent and old segments die out. An abrupt close uses RST.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Networks and Security chapter 5 questions →