Understanding TCP connection states (SYN, ACK, FIN)
Posted: (EET/GMT+2)
The TCP protocol (Transmission Control Protocol) is a key workhorse of the Internet. Many higher-level protocols such as HTTP and FTP rely on it. This post is a quick summary to help you understand how TCP's reliable connections work over TCP/IP. You will also get a brief look at the basic flags used to manage connection state.
A TCP connection is established using a three-step handshake:
Client -> Server: SYN Server -> Client: SYN and ACK Client -> Server: ACK
The SYN flag starts a new connection. The server acknowledges it with SYN+ACK, and the client completes the handshake with one more ACK.
Once a connection is established, data is transferred with sequence numbers. Each byte is numbered, and the receiver acknowledges what has been received.
If data is lost (network failures, etc.), the sender can resend it based on missing acknowledgements.
To close a connection, the FIN flag is used:
Client -> Server: FIN Server -> Client: ACK Server -> Client: FIN Client -> Server: ACK
This ensures both sides finish sending data before the connection is closed.
In practice, you may also see RST (reset) packet being sent when a connection is aborted.
Understanding how TCP protocol operates is very handy when troubleshooting connection issues or understanding packet traces. Even if you are a web developer using just HTTP, having understanding of the lower levels helps.
Hope this helps!