LearnThatStack Ace your next interview
Networking for Developers · question
Question 7 of 51

What is the TCP three-way handshake, and why does it exist?

beginner
← All Networking for Developers questions
Re-explain

The three-way handshake is how two machines agree to start a TCP connection. It takes three messages before any real data flows. Both sides pick a starting sequence number and confirm they can hear each other.

client -> SYN     (let's talk, my seq = x)
server -> SYN-ACK (ok, my seq = y, got your x)
client -> ACK     (got your y, let's go)

SYN means synchronize and ACK means acknowledge. The client's SYN proposes its own starting number. The server's SYN-ACK accepts that number and proposes its own. The final ACK confirms the server's number, so both sides agree.

It exists because TCP promises ordered, reliable delivery, and that promise needs both sides to sync sequence numbers first. The handshake also confirms the path works in both directions. The cost is one round trip of delay before you send data.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Networking for Developers One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • Why isn't a two-way handshake enough? The server's starting number needs confirming too. Also name the stale duplicate SYN that could open a connection nobody asked for.
  • Why are starting sequence numbers hard to guess instead of starting at zero? Cover stray segments from an old connection on the same ports, and attackers guessing numbers to inject or spoof packets.
  • What is a SYN flood, and how can a server survive one? Explain half-open connections filling the backlog, then SYN cookies, which keep the state in the server's sequence number until the final ACK.
  • How many round trips does a new HTTPS connection cost before the first request goes out? Add one TCP round trip to the TLS handshake, which is two round trips on TLS 1.2 and one on TLS 1.3, plus DNS if it is not cached.
  • How does a TCP connection close, and why does it usually take four messages? Each direction closes on its own, so each side sends a FIN and gets an ACK. Mention TIME_WAIT on the side that closes first.

What you can say

  1. The three-way handshake is how two machines agree to open a TCP connection, and it takes three messages before any real data flows.
  2. First the client sends a SYN with its starting sequence number, then the server replies with a SYN-ACK that acknowledges it and proposes its own.
  3. The client's final ACK confirms the server's number, so now both sides agree on where each byte stream starts.
  4. It exists because TCP promises ordered, reliable delivery, and that only works once both sides have synced their sequence numbers.
  5. It also proves the path works in both directions, since each side has heard the other and been heard back.
  6. The cost is one round trip before any data flows, which is why clients reuse connections instead of opening a new one per request.

Weak answers to avoid

  • Recites SYN, SYN-ACK, ACK with no why The names alone show memory, not understanding. Say what each message carries, the sequence numbers, and why both sides must confirm them.
  • Says the handshake makes delivery reliable It only sets up the connection. Retransmission and ordering come later from sequence numbers and ACKs on the data, so say the handshake makes that possible.
  • Never mentions the round-trip cost Interviewers want the trade-off. Say every new connection waits one round trip before data, which is why keep-alive and connection pooling exist.
  • Confuses it with the TLS handshake TCP's handshake syncs sequence numbers. TLS runs after it, on top of the connection, to agree on keys and check certificates. Keep the two layers apart.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Networking for Developers cheatsheet.

← Back to all Networking for Developers questions
Pro · $10/mo

44 of 51 Networking for Developers answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime