TCP is the backbone of most internet traffic. HTTP, HTTPS, SSH, SMTP, and many other protocols all run on top of TCP. Understanding how TCP connections start is one of the most useful things you can learn for packet analysis.
Why the handshake exists
TCP provides reliable, ordered delivery of data. But before two machines can start exchanging data reliably, they need to agree on some parameters: initial sequence numbers, window sizes, and optional features. The three-way handshake is where this negotiation happens.
Every TCP connection you see in a PCAP starts with these three packets. No exceptions.
The three packets
1. SYN (Client to Server)
The client sends a TCP packet with the SYN flag set. This is the client saying "I want to start a connection." The packet includes:
- The client's initial sequence number (ISN). This is a random starting point for numbering the data bytes.
- The Maximum Segment Size (MSS) the client can accept.
- Other options like window scaling and SACK support.
In a packet viewer, you will see this as something like:
12345 → 80 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=64
2. SYN-ACK (Server to Client)
The server responds with both the SYN and ACK flags set. This is the server saying "I acknowledge your request and I also want to connect." It includes:
- The server's own initial sequence number.
- An acknowledgment of the client's sequence number (client's ISN + 1).
- The server's MSS and options.
80 → 12345 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460 WS=128
3. ACK (Client to Server)
The client sends back an ACK confirming the server's sequence number. At this point, the connection is established and data can flow.
12345 → 80 [ACK] Seq=1 Ack=1 Win=65535 Len=0
What to look for
When you see a TCP handshake in a capture, pay attention to:
Timing. The three packets should happen quickly, usually within milliseconds. If there is a long gap between the SYN and the SYN-ACK, the server might be slow to respond or there is network latency. If there is a long gap between the SYN-ACK and the final ACK, the client might be overloaded.
Retransmissions. If you see the same SYN packet repeated, the first one was lost or the server did not respond. Multiple SYN retransmissions usually mean the server is down, a firewall is blocking the connection, or there is a network issue.
RST responses. If the server responds with a RST (reset) instead of a SYN-ACK, the port is closed or the server is refusing the connection. This is normal for port scanning but unusual for legitimate traffic.
To find all TCP handshakes in a capture, use the display filter tcp.flags.syn == 1 && tcp.flags.ack == 0. This shows only the initial SYN packets, each representing the start of a new connection.
What happens after
Once the handshake completes, the connection is open and data flows in both directions. Eventually, one side will close the connection with a FIN packet, starting a similar (but four-step) shutdown process.
If the connection is abruptly terminated, you will see a RST packet instead. This is the TCP equivalent of hanging up the phone without saying goodbye.
What flag combination does the server send in response to a SYN?
You see multiple SYN packets to the same destination port with no SYN-ACK response. What is the most likely cause?
Summary
Three packets, three flags, one connection. SYN, SYN-ACK, ACK. Once you can spot this pattern, you can identify every connection in a capture and understand the state of each one. This is the foundation for everything else in TCP analysis.