TCP
The Transmission Control Protocol gives applications a reliable, ordered byte stream over IP: handshake, sequence numbers, acknowledgements, retransmission and flow control.
- OSI layer
- 4 Transport
- Carried in
- IPv4 / IPv6
- Identified by
- IP protocol 6
- Wireshark filter
tcp- Encrypted
- no
Packet structure
Select a field to see what it does.
Wireshark summarises the flags as [SYN], [SYN, ACK], [ACK], [PSH, ACK], [FIN, ACK], [RST]. The flags byte as hex is handy in filters: 0x002 SYN, 0x012 SYN+ACK, 0x010 ACK, 0x018 PSH+ACK, 0x011 FIN+ACK, 0x004 RST.
How it works
sequenceDiagram
participant C as Client
participant S as Server :443
C->>S: SYN seq=x
S->>C: SYN, ACK seq=y ack=x+1
C->>S: ACK ack=y+1
Note over C,S: Data in both directions (PSH, ACK)
C->>S: FIN, ACK
S->>C: ACK (+ own FIN, ACK)
C->>S: ACK
Note over C: TIME_WAIT (2 × MSL)
Reliability: every byte has a sequence number. The receiver acknowledges the next byte it expects; missing data is retransmitted after a timeout or after three duplicate ACKs (fast retransmit). SACK tells the sender exactly which blocks arrived.
Flow control: the window says how much the receiver can buffer. A zero window pauses the sender. Congestion control (CUBIC, BBR) limits how fast the sender ramps up.
Closing: gracefully with FIN in both directions, or at once with RST.
Port scan responses (what nmap reads):
| Probe | Open port | Closed port | Filtered |
|---|---|---|---|
| SYN | SYN+ACK | RST+ACK | No answer or ICMP unreachable |
ACK (-sA) | RST | RST | No answer |
| FIN / NULL / Xmas | No answer | RST | No answer |
In Wireshark
| Filter | Shows |
|---|---|
tcp.port == 443 | One service, both directions |
tcp.flags.syn == 1 && tcp.flags.ack == 0 | Connection attempts |
tcp.flags == 0x012 | SYN+ACK: the port is open |
tcp.flags.reset == 1 | Resets: closed ports, aborts, IPS kills |
tcp.analysis.flags | Retransmissions, duplicate ACKs, zero windows, out-of-order |
tcp.analysis.retransmission | Retransmissions only (loss) |
tcp.window_size == 0 | Zero windows (slow receiver) |
tcp.stream eq 5 | One connection (right-click › Follow › TCP Stream) |
tcp.flags.syn == 1 && tcp.flags.ack == 0 && tcp.window_size <= 1024 | Typical nmap SYN scan probes |
tcp.flags == 0x029 / tcp.flags == 0x000 | Xmas / NULL scans |
tcp.len > 0 | Segments that carry data |
What normal looks like: handshake, data, FIN exchange. Some retransmissions on the internet. Many SYNs from one source to many ports (or many sources to one port) without completing the handshake is a scan or a SYN flood.
Security notes
- Port scanning: SYN, connect, FIN/NULL/Xmas and ACK scans, see the table above. Half-open SYN scans never complete the handshake.
- SYN flood: many SYNs (often spoofed) fill the server’s half-open queue. SYN cookies defeat it.
- RST injection / hijacking: an attacker who can guess or see the sequence numbers can reset or inject into connections (Great Firewall resets, old blind hijacking). Random ISNs and RFC 5961 checks make blind attacks hard; on-path attackers still can.
- OS fingerprinting: window size, options order, TTL and response to odd flags identify the OS (
nmap -O,p0f). - Evasion: overlapping segments, tiny segments and bad checksums that the IDS accepts but the host drops (or the other way round) can hide payloads from inspection.
- No encryption: TCP payload is plain text unless the application uses TLS or SSH.
Versions and related
- UDP: the connectionless alternative.
- QUIC: reliable streams over UDP with built-in TLS 1.3, used by HTTP/3.
- Extensions: window scale and timestamps (RFC 7323), SACK (RFC 2018), Fast Open (RFC 7413), TCP-AO (RFC 5925).