The TCP 3-way handshake: SYN, SYN-ACK, ACK

☰ All 15 lessons

When you make a phone call, you don't jump straight into the topic. First you say "hello". TCP does exactly the same.

The phone call

The call connects. You say "hello". The other person says "hello" back. Sometimes you ask "can you hear me?" and they say "yes, I can". Now you both know the line works in both directions, and only then do you start talking.

The 3-way handshake, step by step

Say you, the client, want to connect to a web server listening on port 80.

  1. SYN (synchronise): you send a SYN to port 80 on the server's IP. "I want to connect with you."
  2. SYN-ACK: if the server is listening on that port, it replies with an ACK, "I heard you", together with its own SYN, "I want to connect too".
  3. ACK: you acknowledge the server's SYN with one more ACK.

SYN, SYN-ACK, ACK. Only after this does TCP start sending data. It's how TCP keeps things reliable.

TCP 3-way handshake between client and serverClientServer :80SYN: "I want to connect"SYN-ACK: "Heard you, me too"ACK: "Got it"Data flows ⇄
  1. The client sends SYN: "I want to connect."
  2. The server replies SYN-ACK: "I heard you, and I want to connect too."
  3. The client sends ACK: "Got your SYN."
  4. The connection is set up and data starts flowing.
Press "Next step" to watch the handshake.

How hackers use it

The same knowledge is the basis of port scanning. With a tool like Nmap you send a SYN to a port on a server:

  • If a SYN-ACK comes back, the port is open.
  • If an RST (reset) comes back, the port is closed.

Do this only on your own server, or one you have written permission to test. Scanning other people's systems without permission is illegal.

So the 3-way handshake isn't just theory. Tools like Nmap are built on top of it, and you'll see it with your own eyes in Wireshark in lesson 14.

Key takeaways

  • TCP opens every connection with SYN → SYN-ACK → ACK.
  • SYN-ACK back means the port is open; RST means closed.
  • Nmap's SYN scan is built on the handshake.
  • Scan only your own systems or ones you have permission to test.

Quick quiz

Pick an answer to check yourself. Answer both to mark this lesson done.

1. What is the correct order of the TCP 3-way handshake?

  1. A) ACK → SYN → SYN-ACK
  2. B) SYN → SYN-ACK → ACK
  3. C) SYN → ACK → RST
  4. D) SYN-ACK → SYN → ACK
Show answer

Answer: B. The client sends SYN, the server sends SYN-ACK, and the client finishes with ACK. Only then does data flow.

2. Nmap sent a SYN to a port and got a SYN-ACK back. What does that mean?

  1. A) The port is closed
  2. B) The port is open
  3. C) The server is off
  4. D) The connection is UDP
Show answer

Answer: B. A server only sends SYN-ACK if it is listening on that port. A closed port replies with RST.

Frequently asked questions

What is the TCP 3-way handshake?

The three messages TCP exchanges before sending data: the client sends SYN, the server replies SYN-ACK, and the client sends ACK.

Why does TCP use a 3-way handshake?

So both sides know the other can send and receive before any data is transferred, which keeps TCP reliable.

What does RST mean in a port scan?

RST (reset) is the reply from a closed port. A SYN-ACK reply means the port is open.

Do it hands-on.

This tutorial gives you the concepts. The 50 Days Ethical Hacking Challenge puts them to work in real labs, explained in Malayalam.