The TCP three-way handshake opens a connection: the client sends SYN, the server answers SYN-ACK, and the client confirms with ACK. Both sides agree on starting sequence numbers, and data can flow after one round trip.
How it works
Opening
- SYN: the client picks a random initial sequence number and asks to connect.
- SYN-ACK: the server acknowledges it and sends its own sequence number.
- ACK: the client acknowledges the server's number. The connection is ESTABLISHED.
Sequence numbers let each side put data in order and detect what's missing, which is what makes TCP reliable.
What failures look like
- No reply to SYN: a firewall dropped it, or the host is unreachable: a connection timed out after retries.
- RST in reply to SYN: nothing is listening on that port: connection refused.
Closing
Either side sends FIN; the other acknowledges and sends its own FIN. The side that closed first waits in TIME_WAIT for a while to catch stray packets. A RST aborts a connection immediately (connection reset by peer).
Why it matters for speed
The handshake costs a full round trip before data, and TLS adds another. That's why latency matters so much for page loads, and why TLS 1.3, TCP Fast Open and QUIC work to reduce round trips.
Examples
$ sudo tcpdump -i en0 -n 'tcp[tcpflags] & (tcp-syn) != 0 and host 1.1.1.1'
IP 192.168.1.23.53621 > 1.1.1.1.443: Flags [S], seq 1830237467, …
IP 1.1.1.1.443 > 192.168.1.23.53621: Flags [S.], seq 2401195339, ack 1830237468, …
[S] is SYN and [S.] is SYN-ACK. Run curl -sI https://1.1.1.1 in another window to trigger it.
On a Mac
netstat -an -p tcpshows every connection's state: SYN_SENT, ESTABLISHED, TIME_WAIT, CLOSE_WAIT.nc -vz host 443performs just the handshake and reports whether it succeeded.curl -w '%{time_connect}\n' -o /dev/null -s https://example.comprints the handshake time.
See it in the app
LightAtom's connections view shows each app's TCP connections and their state, from the first SYN to close.
Frequently asked questions
What are the three steps of the TCP handshake?
SYN from the client, SYN-ACK from the server, and ACK from the client.
Why does TCP need a handshake?
To agree on starting sequence numbers and confirm both sides can send and receive before any data is exchanged.
Does UDP have a handshake?
No. UDP just sends packets. Protocols built on UDP, like QUIC, add their own handshakes.
What is a SYN flood?
An attack that sends many SYNs without completing the handshake, filling the server's queue of half-open connections. SYN cookies defend against it.