Open the editor

networking · engineering · university · explainer

How to Explain the TCP Three-Way Handshake

The Tracé team · · 2 min read

Before any data flows, TCP opens a connection with three messages: SYN, SYN-ACK and ACK. A sequence diagram, with one vertical line per machine and one arrow per message, is the clearest way to show it, especially when the arrows appear one click at a time.

The three messages

  1. SYN. The client picks an initial sequence number x and sends a segment with the SYN flag set.
  2. SYN-ACK. The server picks its own initial sequence number y and replies with SYN and ACK set, acknowledging x + 1.
  3. ACK. The client acknowledges y + 1. Both sides now know the other's starting sequence number, and data can flow in both directions.
TCP three-way handshake as a numbered sequence diagram
The handshake with its sequence numbers. In class, each arrow appears on a click.

Why three, not two?

Each side must learn that the other received its starting sequence number. Two messages would confirm the client's number to the server, but the server would never know whether its own reached the client. The third message closes that gap. It also protects against an old, delayed SYN opening a ghost connection.

The bigger picture: opening a web page

Students often meet the handshake as an isolated fact. Placing it in a full exchange shows where it fits: a DNS lookup first, then the handshake, then the HTTP request and response.

Sequence diagram: DNS lookup, TCP handshake, then HTTP GET and 200 OK
Three machines, seven messages: DNS, TCP and HTTP in order.

From there it is easy to discuss what a lost message does: draw it with -x and let the class work out which side times out and retransmits.

Build it in Tracé, from text

Open Science → Sequence diagram and write one message per line:

participant C as Client
participant S as Server
C -> S: SYN (seq = x)
S --> C: SYN-ACK (seq = y, ack = x+1)
C -> S: ACK (ack = y+1)
note over C, S: Connection established
  • -> is a message, --> a reply (dashed), -x a lost message.
  • A Mermaid sequenceDiagram can be pasted as it is, including autonumber and Note over.
  • Press Reveal one message per click and present.

The AI builder knows the format too: "explain the TCP handshake and connection teardown, one message per click" gives you the slides to edit.

Questions

Can I show the four-way teardown too?

Yes: FIN, ACK, FIN, ACK between the two lifelines, with a note for the TIME_WAIT state.

Does it work for other protocols?

Any message exchange: TLS, DHCP, a REST call, a radio link's signalling, or a classroom dialogue between three characters.

Make this slide yourselfFree to start, in your browser, no code. Present it, share a link or export a video.
Open the editor

More: Animated math slides for teachers · How to create math slides, step by step

New free slides by emailWhen new free slides and lessons come out. No spam, and one click to unsubscribe.