← Lessons

quiz vs the machine

Gold1360

Networking

The TCP Three Way Handshake

See how two hosts agree on sequence numbers before any data flows.

4 min read · core · beat Gold to climb

Establishing a Connection

TCP is connection oriented, so before sending data the two hosts perform a three way handshake to synchronize state and choose starting sequence numbers.

The Three Steps

  • The client sends a SYN segment with its initial sequence number.
  • The server replies with a SYN ACK, acknowledging the client and sending its own sequence number.
  • The client sends a final ACK, after which the connection is established.

Each side now knows the other's starting sequence number, which lets TCP detect loss, reorder segments, and avoid mixing data from old connections.

Why It Costs a Round Trip

The handshake adds one full round trip of latency before any application bytes move. On high latency links this matters, which is why connection reuse, keep alive, and protocols like QUIC that fold setup into fewer trips are valuable.

Closing Down

Connections close with a separate exchange of FIN and ACK segments, letting each direction shut independently.

Key idea

TCP trades one round trip of setup for reliable, ordered delivery by exchanging SYN, SYN ACK, and ACK to agree on sequence numbers.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the correct order of the handshake segments?

2. What does the handshake primarily establish?