How the TCP Three-Way Handshake Works, in Plain English

Diagram of the TCP 3-way handshake showing SYN, SYN-ACK and ACK packets moving between a client and a server

Every time you open a website, something quiet happens before the first word of the page arrives. Your device and the server do a short, three-step exchange to agree they are both ready to talk. That exchange is the TCP three-way handshake.

You never see it. It usually finishes in a fraction of a second. But it is the reason a page can load in the right order, and why a dropped connection can be noticed and repaired, instead of leaving you with a half-finished download.

Animated diagram of the TCP 3-way handshake showing SYN, SYN-ACK and ACK packets moving between a client and a server
A short animation of the TCP three-way handshake: SYN, SYN-ACK and ACK, then data begins to flow.

What TCP is actually for

The internet moves data in small chunks called packets. The Internet Protocol, or IP, gets those packets to the right address, but it does not check whether they all arrived, or arrived in order. That job belongs to the Transmission Control Protocol, or TCP.

As Mozilla’s MDN glossary puts it, TCP lets two machines exchange a stream of data and aims to deliver it reliably and in the same order it was sent. Before any of that data goes out, the two sides need to agree on a starting point. That agreement is the handshake.

Three messages: SYN, SYN-ACK, ACK

The current TCP specification, RFC 9293, describes the usual setup as a three-way, or three-message, handshake. MDN uses the same three labels you will see in most diagrams:

  1. SYN. Your device, the client, sends a synchronize message: “I want to connect, and I will start numbering my data from x.” That number x is its initial sequence number.
  2. SYN-ACK. The server replies with both a synchronize and an acknowledgement: “I received x, and I will start numbering my data from y.” The acknowledgement number is x+1, which tells the client the SYN was received.
  3. ACK. Your device sends an acknowledgement of y, written as ack=y+1. The connection is now established, and data can flow in both directions.

Those letters x and y stand in for large random numbers, not the literal characters. Each side picks its own starting number. The SYN itself counts as one number in the sequence, which is why the other side acknowledges x+1 and y+1, not x and y.

In teaching diagrams, the third packet is often labelled only with its acknowledgement, ack=y+1. In the real protocol that packet also carries the client’s next sequence number, usually x+1. The meaning is the same: “I got your SYN, we are ready.”

What happens once the door is open

After the handshake, both sides are in the “established” state. TCP can then send the actual page data, keep track of what has arrived, and ask for anything missing to be sent again.

If you are visiting a site over HTTPS, which is the lock you see in the address bar, a second handshake still has to happen. MDN’s guide to how browsers work notes that the TCP handshake comes after the DNS lookup and before the TLS handshake that sets up encryption. Opening https://knowgrasp.com, for example, uses TCP on port 443, the usual port for HTTPS.

When a page does not use this handshake

Not every modern page uses TCP. HTTP/3, standardised in RFC 9114, runs on QUIC, a transport that travels over UDP rather than TCP. MDN’s QUIC glossary puts it plainly: QUIC is used instead of TCP as the transport layer in HTTP/3. QUIC has its own handshake, and it folds in TLS 1.3, so you do not get the classic SYN, SYN-ACK, ACK sequence on those connections. Plenty of everyday browsing still uses HTTP/1.1 or HTTP/2 over TCP, which is why this handshake is still worth knowing.

How servers stay standing in a SYN flood

Attackers can abuse this setup. In a SYN flood, the attacker sends a huge number of opening SYN packets, often with fake return addresses, and never finishes the handshake. The server can be left holding many half-open connections until it has no room for real users. That is a protocol-style DDoS, which we cover in more detail in the DDoS explainer.

One common defence is SYN cookies, described in RFC 4987 and in Daniel J. Bernstein’s original write-up. Instead of storing a block of state for every half-open connection, the server encodes what it needs in the sequence number of its SYN-ACK. A genuine client will send back the right acknowledgement; a flood of spoofed SYNs will not. Linux can turn this on when a socket’s SYN queue overflows. It is a fallback under stress, not something a browser user has to configure.

How to spot the handshake in a packet capture

If you open a capture in Wireshark, you can filter for the opening flag with this display filter:

tcp.flags.syn == 1

That shows every packet with the SYN flag set, including the server’s SYN-ACK. To see only the client’s opening SYN, tighten it to tcp.flags.syn == 1 and tcp.flags.ack == 0. You do not need to do this to use the web. It is just a way to watch the same three steps the animation is teaching.

You do not need to run this handshake yourself. Your browser and the server already know the steps. What is useful is being able to recognize them. When a later article talks about a SYN flood, a stalled connection, or a site that never quite finishes loading, this is the short conversation those problems are interrupting.

Common questions

Do I have to send these packets myself?

No. Your browser, or any ordinary app that opens a TCP connection, already does it. The useful part is being able to recognise the three labels when they show up in an article, a diagram or a packet capture.

What is a SYN flood?

It is a protocol attack that fires a large number of SYN packets at a server and does not complete the handshake, so the server wastes effort on connections that will never finish. SYN cookies are one way servers reduce the damage.

Does every website use this handshake?

Any site you reach over ordinary TCP, including most HTTPS on port 443, does. Connections that use HTTP/3 over QUIC do not, because QUIC runs on UDP and has its own handshake.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *