What a flag is
Right after the data offset, the TCP header has a block of single-bit flags. Each one is either 0 or 1. Together they answer two questions about the segment: what is it for (open, close, abort, ordinary data) and which other fields should the receiver trust (for instance, the acknowledgement number is only meaningful when ACK is set).
The flags one at a time
- SYN (synchronise): opens a connection. Set in the first segment from each side, which carries that side's initial sequence number. It uses up one sequence number.
- ACK (acknowledge): the acknowledgement number field is valid. Set on every segment after the first SYN, so most segments on the wire carry it.
- FIN (finish): the sender has no more data. Each direction is closed with its own FIN, and it also uses up one sequence number.
- RST (reset): abort the connection immediately. Sent when a segment arrives for a port nobody is listening on, or for a connection the host does not know.
- PSH (push): deliver the data to the application now instead of waiting to fill a buffer. Common at the end of a request or response.
- URG (urgent): the urgent pointer field is valid. Almost never used by modern software.
- ECE and CWR: explicit congestion notification. A router marks packets instead of dropping them, the receiver echoes the mark with ECE, and the sender confirms it has slowed down with CWR.
Combinations you will see
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Reading flags in a capture
# tcpdump: only segments that open a connection (SYN without ACK)
tcpdump -nn 'tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn'
# Wireshark display filters
tcp.flags.syn == 1 && tcp.flags.ack == 0
tcp.flags.reset == 1Counting SYNs without matching SYN-ACKs shows a host being scanned or a server that is not answering. A burst of RSTs from one address means the port is closed or a firewall is rejecting with reset.
$tcpdump -nn -i eth0 tcp port 443 10:01:02.100 IP 192.0.2.10.51514 > 198.51.100.20.443: Flags [S], seq 1000, win 64240, length 0 10:01:02.130 IP 198.51.100.20.443 > 192.0.2.10.51514: Flags [S.], seq 7000, ack 1001, win 65535, length 0 10:01:02.130 IP 192.0.2.10.51514 > 198.51.100.20.443: Flags [.], ack 7001, win 502, length 0
Unusual flags and what they suggest
- No flags at all (a "null" segment) and FIN+PSH+URG (an "Xmas" segment) are not valid in a real conversation. Scanners send them to see how a stack answers.
- Many SYNs, few ACKs can be a SYN flood: the attacker never completes the handshake, so the server's half-open connection table fills. SYN cookies are the usual defence.
- RST in reply to your SYN means the port is closed. Silence usually means a firewall dropped it.
TCP flags in short
- SYN opens, FIN closes a direction, RST aborts, ACK acknowledges.
- SYN+ACK is flag value 0x12; ACK alone is 0x10.
- SYN and FIN each use one sequence number; a plain ACK uses none.
- PSH asks for prompt delivery; URG and its pointer are legacy.
Test yourself
A server receives a segment for port 8080, where nothing is listening. Which flag does its reply carry?
Which flags make up the second step of the three-way handshake?
tcpdump shows Flags [P.] on a segment. Which flags are set?
What does a flood of SYN segments with no final ACK usually indicate?
Which flag tells the receiver that the acknowledgement number field is meaningful?