TCP Connection Protocol (TCP) States – In IT Networking, when we stream or browse or data copy there is always a connection between 2 or more systems and these are going through different TCP states, once we understand them clearly it will be easy for us to understand what and where can be bottleneck/issue, improve performance, security.
TCP operates in the transport layer of OSI model. TCP Ensures reliable network communication.
What are packets ?
Packets are nothing but a smaller chunk/block/group of information/data that is being transferred over the network. Every packet when travelling over the network is independent and they are re-assembled once they all reached the destination to reconstruct the original data.
Packets contain 3 main components to reconstruct the original data - Header, Payload, Trailer.
For every TCP connection that is happening in the networking world below can be the different states,
LISTEN
This is the state where the server passively waits for incoming connection requests. It listens for SYN (synchronization) packets from clients that wish to establish a connection.
SYN-SENT
This state occurs when a client initiates a connection by sending a SYN packet. The client waits for an acknowledgment from the server to move forward.
SYN-RECEIVED
The server receives the SYN packet and responds with both a SYN and an ACK (acknowledgment). This confirms that the server is ready for the handshake.
ESTABLISHED
Once both sides exchange SYN and ACK packets, the connection is fully established. This is where data transmission occurs. Applications can send and receive packets smoothly.
FIN-WAIT-1
When one side wants to close the connection, it sends a FIN (finish) packet. It waits for an acknowledgment from the other side.
CLOSE-WAIT
The receiving party acknowledges the FIN packet and enters CLOSE-WAIT. It may still send remaining data before fully closing the connection.
FIN-WAIT-2
The initiating party receives the ACK and waits for the second FIN packet from the other end.
LAST-ACK
The second party sends a FIN and waits for the final acknowledgment.
TIME-WAIT
The connection enters TIME-WAIT, ensuring the last ACK was received. This prevents old duplicate packets from interfering with new connections.
CLOSED
Finally, the connection is fully terminated, and all resources are freed.
Sharing a real-world example of a user browsing on a website.
Imagine you’re opening a website in your browser. Here’s how TCP connection states apply:
- LISTEN
- SYN-SENT
- SYN-RECEIVED
- ESTABLISHED
- FIN-WAIT-1
- CLOSE-WAIT
- FIN-WAIT-2
- LAST-ACK
- TIME-WAIT
- CLOSED
LISTEN
This is the state where the server passively waits for incoming connection requests. It listens for SYN (synchronization) packets from clients that wish to establish a connection.
SYN-SENT
This state occurs when a client initiates a connection by sending a SYN packet. The client waits for an acknowledgment from the server to move forward.
SYN-RECEIVED
The server receives the SYN packet and responds with both a SYN and an ACK (acknowledgment). This confirms that the server is ready for the handshake.
ESTABLISHED
Once both sides exchange SYN and ACK packets, the connection is fully established. This is where data transmission occurs. Applications can send and receive packets smoothly.
FIN-WAIT-1
When one side wants to close the connection, it sends a FIN (finish) packet. It waits for an acknowledgment from the other side.
CLOSE-WAIT
The receiving party acknowledges the FIN packet and enters CLOSE-WAIT. It may still send remaining data before fully closing the connection.
FIN-WAIT-2
The initiating party receives the ACK and waits for the second FIN packet from the other end.
LAST-ACK
The second party sends a FIN and waits for the final acknowledgment.
TIME-WAIT
The connection enters TIME-WAIT, ensuring the last ACK was received. This prevents old duplicate packets from interfering with new connections.
CLOSED
Finally, the connection is fully terminated, and all resources are freed.
Sharing a real-world example of a user browsing on a website.
Imagine you’re opening a website in your browser. Here’s how TCP connection states apply:
- LISTEN – The web server is waiting for incoming connections.
- SYN-SENT – Your browser sends a SYN packet to the server, requesting a connection.
- SYN-RECEIVED – The server responds with a SYN-ACK, acknowledging the request.
- ESTABLISHED – Your browser sends an ACK, completing the handshake. Now, data (webpage content) can be exchanged.
- FIN-WAIT-1 & FIN-WAIT-2 – When you close the tab, your browser sends a FIN packet to terminate the connection.
- TIME-WAIT & CLOSED – The server acknowledges the termination, ensuring no stray packets interfere with future connections.
Understanding basics and organized work culture is key to efficient Troubleshooting!!!
Happy Troubleshooting!!!