Checking the line before talking
Before you tell a friend something important on the phone, you check that they are there: “Hello, can you hear me?” “Yes, can you hear me?” “Yes.” Only then do you start talking. In the basic exchange shown here, TCP checks readiness before ordinary application data. This short exchange is the three-way handshake.
SYN, SYN-ACK, ACK
Keep two checks separate. IP reachability gets the SYN to the server; a listening TCP service and the relevant host/firewall rules determine whether it can accept this connection. The server does not use the browser's source port as its own listening port. In this example it listens on 443 and sends its reply back to the client's temporary port 52000.
A completed TCP handshake proves that TCP connection setup succeeded; it does not prove that TLS, login or the web application will succeed. For a typical HTTPS connection, TLS negotiation follows TCP setup. TLS is the security protocol that authenticates and encrypts the application conversation. A failure there is a different troubleshooting stage.
The handshake is made of three segments, each named after the flags it carries:
- SYN: the client asks to open a connection and sends its initial sequence number (ISN), the starting point for numbering its bytes.
- SYN-ACK: the server agrees. It sends its own ISN (SYN) and acknowledges the client's SYN (ACK).
- ACK: the client acknowledges the server's SYN. The connection is now open in both directions.
Press play to watch the handshake.
Following the sequence numbers through the handshake
Real ISNs are large, hard-to-guess numbers. To keep this example readable, the client starts at 1000 and the server at 5000. Tap a message to see its fields.
- Client next byte:
- 1001
- Server next byte:
- 5001
Device key: Client (laptop)
Arrows run from each message's sender to its receiver. Rows show message order, not separate cables or elapsed time to scale. Port numbers identify services or conversations, not physical switch sockets.
Reading the addresses
IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.
An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.
- Client: 192.168.1.20:52000
- Web server: 203.0.113.10:443
LISTEN to ESTABLISHED: the connection states
Each side keeps track of where it is in the process. This is called its connection state. You will see these names in netstat output and in firewall logs.
| State | Who | Meaning |
|---|---|---|
| LISTEN | Server | Waiting for a SYN on a port |
| SYN-SENT | Client | Sent a SYN; waiting for a SYN-ACK |
| SYN-RECEIVED | Server | Received a SYN and sent a SYN-ACK; waiting for the final ACK |
| ESTABLISHED | Both | Handshake done; data can flow both ways |
Why four jobs fit into three messages
Each side has its own sequence numbers, and each side must know that the other has received its starting number. That needs a SYN and an ACK in each direction: four jobs. The server puts its SYN and its ACK in the same segment, so the four jobs fit into three messages.
Random ISNs matter too. If every connection started at 0, an old, delayed segment from a previous connection could be mistaken for new data. A random starting number also makes it much harder for an attacker to guess the numbers and inject fake segments.
If nothing is listening on the port, the server replies to the SYN with an RST (reset) instead of a SYN-ACK. If a firewall silently drops the SYN, the client gets no reply at all. It sends the SYN again a few times, then gives up with a timeout.
Testing a TCP port with telnet from a router
A Cisco router can test whether a TCP port answers: run telnet with an IP address and a port number, and the router tries to open a TCP connection to that port. The output below is based on Cisco documentation, not captured from a lab device.
R1#telnet 203.0.113.10 443 Trying 203.0.113.10, 443 ... Open
disconnect.R1#telnet 203.0.113.10 8080 Trying 203.0.113.10, 8080 ... % Connection refused by remote host
That difference between “refused” and “timed out” is one of the quickest clues in troubleshooting. Refused points at the server or its application; a timeout points at the path or a firewall in between.
Test yourself on the handshake
A client opens a connection with a SYN that has sequence number 7000. Which acknowledgement number is in the server's SYN-ACK?
You test a web server on port 8080. Your client sends a SYN and immediately gets an RST back. What does this most likely mean?
A server has received a SYN and sent its SYN-ACK, but the client's final ACK has not arrived yet. Which state is the server in?
Technical references
RFC 9293: base TCP header, connection state, sequence space and delivery.