How does the TCP three-way handshake work?
The TCP (Transmission Control Protocol) three-way handshake is three tiny messages, SYN, SYN-ACK, and ACK, that your device and a server usually trade to open a connection before page data moves.

TCP three-way handshake
TCP (Transmission Control Protocol) is the set of rules many web connections run on. HTTP/1.1 and HTTP/2, two versions of HTTP (Hypertext Transfer Protocol), both use it. Before any page data moves, your device and the server trade three tiny messages to open the connection. That exchange is the three-way handshake, described in RFC (Request for Comments) 9293, the TCP standard.
The handshake only opens the road. It doesn’t prove who’s answering, and it encrypts nothing. That’s why TLS (Transport Layer Security) exists: it runs after the handshake, checks the server with a certificate, and encrypts the data. Not every page load starts this way, though. HTTP/3 runs over QUIC on UDP (User Datagram Protocol) and has no TCP handshake at all.
What the handshake actually sends
Each message is a TCP header with flags set, and normally no data yet. The first carries the SYN (synchronize) flag. The reply carries SYN and ACK (acknowledge) together. The last carries only ACK. Next to the flags sits a 32-bit sequence number field. Each side picks its own starting value, the initial sequence number (ISN), and uses it to count the bytes it sends.
RFC 6528 says the ISN should come from a clock plus a secret keyed function, so an attacker off the path can’t guess it. It isn’t a password, though. The same RFC calls hard-to-guess ISNs a palliative measure, not a replacement for cryptographic authentication. In a capture made with tcpdump -n -S, which prints absolute sequence numbers, the three messages show up as Flags [S], Flags [S.], and Flags [.].
How the handshake opens a connection
- Your device sends SYN. It asks to talk and includes its hard-to-guess starting number.
- The server answers SYN-ACK. It confirms your number plus one, meaning ‘got it,’ and adds its own starting number. The plus one is there because a SYN uses up one sequence number, so the ACK field names the next number expected.
- Your device sends ACK. It confirms the server’s number plus one. The connection is now established.
- Data starts to flow. Because both sides know each other’s starting numbers, they can spot lost pieces and resend them.
If no SYN-ACK comes back, the operating system resends the SYN. On Linux the default is 6 retries, set by tcp_syn_retries. When those run out, the browser reports a timeout, for example Chrome’s ERR_CONNECTION_TIMED_OUT. If the port is closed and the server answers with a reset, RST, you get ‘connection refused’ instead.
The handshake is not security
A completed handshake can feel like a verified connection, but it isn’t. TCP has no authentication and no encryption. Finishing the three messages only shows the other side can receive packets at that address. Checking who the server is and hiding your data is the job of TLS, for example HTTPS (HTTP Secure) on port 443, and it starts only after the handshake. Three messages open the road, but they don’t lock it.
What to do
- Before you type a password, make sure the address starts with
https. TLS, not the handshake, checks the server and encrypts your data. - Read ‘connection timed out’ as a knock nobody answered: your SYN got no SYN-ACK back.
- Read ‘connection refused’ differently: the server did answer, but with a reset, because the port is closed.
- Want to see it yourself? Run
tcpdump -n -Son your own machine and look for[S],[S.], and[.]when a connection opens.
Watch it in 60 seconds
