TCP establishes a connection with a 3-way handshake, closes it with a 4-way teardown, and keeps data flowing safely with flow control and congestion control. The handshake synchronizes each side's starting sequence number so both can track and acknowledge every byte:
3-WAY HANDSHAKE (open) 4-WAY TEARDOWN (close)
Client Server Client Server
│──── SYN ───────▶│ │──── FIN ───────▶│
│◀── SYN, ACK ────│ │◀──── ACK ───────│
│──── ACK ───────▶│ │◀──── FIN ───────│
│ connected │ │──── ACK ───────▶│
