The TCP Three-Way Handshake, and How to Watch It Live
What SYN, SYN-ACK and ACK actually mean, why sequence numbers matter, and how to see the whole handshake on your own machine with ss and tcpdump.
Every reliable connection on the internet — every web page, every SSH session, every API call — starts with the same three-packet ritual. Understand it once and a huge amount of networking stops being mysterious.
Why a handshake at all?
TCP promises reliable, ordered delivery over an unreliable network. To do that, both sides must agree on a starting point before any data flows: an initial sequence number each will use to number its bytes. The handshake is how they exchange and acknowledge those numbers.
The three packets
Client Server
│ ── SYN seq=x ──────────▶ │ "let's talk; my bytes start at x"
│ ◀── SYN-ACK seq=y ack=x+1 ─│ "ok; mine start at y, got your x"
│ ── ACK ack=y+1 ─────────▶ │ "got your y; we're connected"
│ │
│ ===== data flows ===== │- SYN — the client picks a random initial sequence number
xand sends a segment with the SYN flag set. - SYN-ACK — the server picks its own
y, acknowledges the client'sx(by sendingack = x+1), and sets both SYN and ACK flags. - ACK — the client acknowledges the server's
ywithack = y+1. The connection is nowESTABLISHEDon both ends.
The +1 is because SYN itself consumes one sequence number, even though it carries no data.
See it yourself
Watch a handshake happen in real time. In one terminal, start a capture filtered to one host and port:
sudo tcpdump -n -i any 'tcp port 443 and host example.com'In another, make a single connection:
curl -s -o /dev/null https://example.comYou will see the three segments go by, flagged [S], [S.] and [.] — tcpdump's shorthand for SYN, SYN-ACK and ACK.
Check connection states without a capture using ss:
ss -tan state syn-sent # connections mid-handshake
ss -tan state established # fully openConnection teardown (the four-way goodbye)
Closing is the handshake's mirror image, but it takes four steps because each direction is shut independently with FIN/ACK. A gracefully closing socket passes through FIN-WAIT, CLOSE-WAIT and finally TIME-WAIT — the deliberate pause that lets any straggling packets drain before the port is reused.
ss -tan state time-wait | head # sockets waiting out the drainCommon things that go wrong
- No SYN-ACK, repeated SYNs → nothing is listening, or a firewall is silently dropping. (A firewall that rejects would send an RST instead.)
- Immediate RST → the port is closed and the host is actively refusing.
- Handshake completes but TLS stalls → the TCP layer is fine; look higher up.
Takeaways
- SYN → SYN-ACK → ACK synchronises a random sequence number in each direction.
- Sequence/ack numbers are how TCP guarantees order and reliability.
tcpdumpshows the packets,ssshows the resulting states — reach for them before guessing.