Concepts / TCP connections

TCP connections

Three-way handshake

Also called SYN, SYN-ACK, handshake, FIN

SYN, SYN-ACK, ACK: how TCP opens a connection, each side agreeing on starting sequence numbers.

Three segments, and each side knows where the other starts
Three segments, and each side knows where the other starts

Each side picks its own first sequence number (1000 and 5000 here; real ones are random). A SYN counts as one byte, so each acknowledges the other's number plus one: ack 1001, ack 5001. The options, MSS and window scale, ride only in the two SYNs. After the third segment both sides are ESTABLISHED and data starts at 1001 and 5001.

The client asks (SYN), the server agrees and acknowledges (SYN-ACK), the client acknowledges (ACK); then data flows. Each side closes its direction with a FIN. Options like the MSS and window scaling are agreed in the SYNs.

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab