Chapter 9: TCP Under the Microscope: Handshakes, Retransmissions, and Sequence Analysis
Wireshark’s expert analysis tags TCP packets with labels: [TCP Retransmission], [TCP Dup ACK], [TCP Out-Of-Order], [TCP ZeroWindow]. They read like verdicts, but each is an inference Wireshark draws from the sequence numbers it has seen so far in one stream. Misread one, and you blame a server for a network problem, or blame the network for a server problem. This chapter shows the sequence-number math behind each label and how to attribute the cause to the client, the network, or the server. It starts with the TCP handshake, because the handshake sets the sequence numbers every label is measured against.
The Three-Way Handshake as Captured
A completed handshake starts with a SYN, and the Info column names each of its three packets for you [29, 199]. The client opens with a SYN that proposes the connection and its own starting sequence number. The server answers SYN, ACK to accept and propose its own. The client closes the loop with a final ACK, and data begins to flow [29, 199]. The first three frames of lab/http.cap, a web download captured at the client, are a healthy handshake [155]:
1 $ tshark -r http.cap -c 3
2 1 0.000000 145.254.160.237 → 65.208.228.223 TCP 62 3372 → 80 [SYN] Seq=0 Win=8760 Len=0 MSS=1460 SACK_PERM
3 2 0.911310 65.208.228.223 → 145.254.160.237 TCP 62 80 → 3372 [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1380 SACK_PERM
4 3 0.911310 145.254.160.237 → 65.208.228.223 TCP 54 3372 → 80 [ACK] Seq=1 Ack=1 Win=9660 Len=0
Start with the numbers, because the labels only restate them. The SYN’s Seq=0 is the client’s proposed initial sequence number. The SYN-ACK’s Ack=1 acknowledges that proposal by counting it as one consumed byte, and the ACK’s Seq=1 Ack=1 closes the loop [19, 199]. Both SYN and FIN consume one sequence position each, so this bookkeeping applies to the connection’s setup and teardown as much as to its data [199, 200].
Captured at the client, the SYN to SYN-ACK interval is a full round-trip to the server, a free RTT measurement that no ICMP ping can fake. Routers often deprioritize ICMP, so this timing reflects what the application’s own traffic experiences [29, 148, 201]. Captured mid-path, that same interval covers only part of the journey, so measure the SYN through final-ACK span, which includes both halves [201]. Wireshark records the SYN-to-final-ACK interval as tcp.analysis.initial_rtt and sets it only once the handshake completes, so a conversation carrying that field finished its handshake [202]. In http.cap the SYN-ACK arrives 0.911 s after the SYN and the final ACK leaves in the same instant, so tcp.analysis.initial_rtt is 0.911 s as well [203]. To find half-open connections, SYN/SYN-ACK without the final ACK, query (tcp.flags==0x12) and not tcp.analysis.initial_rtt [202]. In tshark, add -2, because a single pass has not yet seen the final ACK when it reaches the SYN-ACK.
Three connection failures show up in the handshake itself. A SYN with no SYN-ACK means something drops it without answering, usually a firewall. A SYN answered by RST, ACK means the port is closed and actively refused. Repeated SYNs at growing intervals are the client retrying a path that will not answer [29]. Isolate all of them with tcp.flags.syn == 1 || tcp.flags.fin == 1 || tcp.flags.reset == 1, which shows where each connection in the file starts and ends [29]. tcp.flags.syn == 1 also matches SYN-ACKs. For SYN-only traffic, use tcp.flags == 0x02 as a load filter in the open-file dialog [204].
Teardown: FIN versus RST
Graceful close mirrors the handshake. The side with nothing left to send transmits FIN, the other side ACKs it, then the reverse happens, four packets total. Each FIN consumes one sequence position, just as the SYN did [19, 205]. Filter with tcp.flags.fin == 1. An RST is different. It aborts the connection immediately with no close handshake, appearing after a crash, an application abort, or a refused connection [205, 146]. tcp.flags.reset == 1 isolates the resets, including the [RST, ACK] refusals that punctuate your captures. To classify whole conversations rather than packets, use the tcp.completeness field, whose bits are 1=SYN, 2=SYN-ACK, 4=ACK, 8=data, 16=FIN, and 32=RST; tcp.completeness==7 (SYN + SYN-ACK + ACK) finds handshake-only connections [206].
Sequence and Acknowledgment Numbers
The handshake looks trivial because Wireshark shows you relative sequence numbers by default. It subtracts the stream’s initial sequence number so the first segment reads Seq=0 [19, 205]. The raw 32-bit values are still there. Uncheck “Relative sequence numbers” under Edit > Preferences > Protocols > TCP to see them [9, 205]. Keep relative numbers on for everyday reading, and keep the preference path in mind when two engineers disagree about a trace.
TCP numbers bytes, and it numbers each direction independently [200]. The sequence number of a segment names the first byte it carries. The acknowledgement number names the next byte the receiver expects, and it is cumulative. One value confirms all earlier bytes, which is why losing a pure ACK is cheap [200]. That two of the three handshake packets show Seq=0 Ack=1 and the third Seq=1 Ack=1 is just this rule applied to the SYN’s one consumed byte [19, 199].
Once data flows, the numbers advance by segment size. These are frames 4 to 12 of http.cap, with the columns frame, source, relative sequence number, acknowledgement number and payload length [207]:
1 4 145.254.160.237 1 1 479 GET /download.html HTTP/1.1
2 5 65.208.228.223 1 480 0 80 → 3372 [ACK] Seq=1 Ack=480 Win=6432 Len=0
3 6 65.208.228.223 1 480 1380 HTTP/1.1 200 OK
4 7 145.254.160.237 480 1381 0 3372 → 80 [ACK] Seq=480 Ack=1381 Win=9660 Len=0
5 8 65.208.228.223 1381 480 1380 80 → 3372 [ACK] Seq=1381 Ack=480 Win=6432 Len=1380
6 9 145.254.160.237 480 2761 0 3372 → 80 [ACK] Seq=480 Ack=2761 Win=9660 Len=0
7 10 65.208.228.223 2761 480 1380 80 → 3372 [ACK] Seq=2761 Ack=480 Win=6432 Len=1380
8 11 65.208.228.223 4141 480 1380 80 → 3372 [PSH, ACK] Seq=4141 Ack=480 Win=6432 Len=1380
9 12 145.254.160.237 480 5521 0 3372 → 80 [ACK] Seq=480 Ack=5521 Win=9660 Len=0
The GET carries bytes 1 to 479, so the server’s ACK in frame 5 says 480, the next byte it expects. Each server segment carries 1380 bytes and moves the sequence number up by that much: 1, 1381, 2761, 4141. Frame 12’s Ack=5521 covers frames 10 and 11 at once, because one cumulative ACK confirms all the bytes below it. When you suspect a byte is lost, find the ACK that stops advancing. The retransmission’s sequence number will equal that stalled ACK number, and that equality pins the exact missing segment [19].
Retransmissions: What They Mean and How to Count Them
TCP has no header flag that says “this is a retransmission.” Wireshark infers the label by tracking each stream’s state (comparing a segment’s sequence number, IP ID, addresses, ports, and arrival time against what it has already seen) and prepends [TCP Retransmission] to the Info column when a segment repeats [208, 209]. The dissector runs this analysis once per packet when the file opens, and the “Analyze TCP sequence numbers” toggle in Preferences > Protocols > TCP turns it on or off for the whole file [206].
A retransmission follows a timeout, when the sender’s retransmission timer (RTO) expires before an ACK arrives. The sender re-sends and doubles the wait next time, in exponential backoff [209, 19]. A fast retransmission happens reactively, before the timer fires, after the sender collects three duplicate ACKs [209, 138, 200]. Fast recovery after duplicate ACKs is ordinary loss handling. Waiting out a full RTO means no feedback path, which points to severe loss, a broken return path, or an endpoint problem [210].
A retransmission proves only that TCP’s sender decided to resend bytes. It does not prove the packet was dropped on the wire. The copy may have arrived late, a spurious retransmission after an over-aggressive timeout, or the capture itself may have dropped a frame, leaving a gap that later flags a segment as a retransmission even though the network delivered it [208, 138, 200].
Counting and the Rate
A rate based on bytes is more precise than one based on packets, but packet counts are a serviceable estimate. One way to get both numbers from the command line:
1 tshark -r capture.pcap -q -z io,stat,1,"tcp.analysis.retransmission"
2 TOTAL=$(tshark -r capture.pcap | wc -l)
3 RETRANS=$(tshark -r capture.pcap -Y 'tcp.analysis.retransmission' | wc -l)
The -z io,stat,1 tap prints packet counts per one-second interval restricted to the filter. Dividing RETRANS / TOTAL gives a rough rate, and the denominator must count every packet in the file [138]. Filter the retransmits by direction, tcp.analysis.retransmission and ip.src == 10.0.0.50, before you judge either side [138].
Then open each one before you quote the rate. In http.cap the filter matches one frame of 43, frame 36, a naive rate of 2.3% [211, 212]. Frame 36 also carries the spurious-retransmission flag, and frame 37 is the client’s duplicate ACK for data it already held [211, 213]. Nothing was lost, so the true loss rate of this capture is zero.
For timing, learn what a normal backoff looks like. A Windows sender retransmits up to five times with doubling gaps, roughly 9.6 seconds total, before giving up [19]. A VNC thin-client capture shows that a fast retransmit does not guarantee recovery. The server resent the segment after the third duplicate ACK, but the client still did not acknowledge it, so the sender fell back to slow timeout retransmissions. Closer analysis found that the server’s stack mishandled ACKs that split a segment and used a fixed RTO of about 500 ms. The slow recovery was sender behavior, made worse by the client’s tiny receive window [214].
Duplicate ACKs and Fast Retransmit
A duplicate ACK is the receiver repeating the same acknowledgment value because it detected a gap. The ACK number is lower than the last byte the sender transmitted, so the receiver re-acknowledges it once for every segment that arrives past the hole [209, 215]. The Info column annotates the count. [TCP Dup ACK 8796#16] means the receiver sent the identical ACK seventeen times [215]. Occasional duplicates are normal on any path with slight reordering. A long run means the receiver is parked at a gap [215, 216].
Three consecutive duplicate ACKs, with no intervening progress, is the sender’s evidence that the segment at the ACK number is probably lost, so it fast-retransmits that single segment instead of waiting out the RTO [209, 216, 200]. This three-ACK threshold is deliberate. One or two duplicates are consistent with reordering, and three-plus strongly indicate real loss [217]. Distinguish the two outcomes by what follows:
- Loss: the dup-ACK sequence ends in a fast retransmission (
tcp.analysis.fast_retransmission). - Reordering: the expected segment finally arrives and the gap closes without any retransmission [216].
Wireshark exposes the count as a filterable field, so highlight only ACKs past the threshold with tcp.analysis.duplicate_ack_num >= 3 [216].
Out-of-order is the label for the segment that arrives with a sequence number lower than the previously seen packet on that connection [209]. It is not itself loss. The duplicate ACKs may just be your only view of it. Possible causes span network reordering, parallel paths, load-balanced links, capture behavior, and loss where the original arrives late [140]. The related Previous segment not captured label (tcp.analysis.lost_segment) is stronger. It marks the packet whose sequence number jumped past the next expected value, meaning one or more earlier segments were not observed, usually followed by a retransmission of that range [209, 19].
lab/smtp.pcap shows how far an out-of-order label can be from reordering [218]. The client sends four 1460-byte segments, frames 22 to 25. A router answers with four ICMP Fragmentation needed messages, frames 26, 28, 29 and 30, because those segments are too big for the next link. The client then resends the same data in 1452-byte segments. Wireshark labels the first resend, frame 27, a retransmission, and the next four, frames 32, 33, 35 and 36, out-of-order, because their sequence numbers are lower than the highest already seen. Nothing was reordered and nothing was lost on the wire. This is Path MTU Discovery doing its job, and only the ICMP messages beside the labels show it.
Interpret these labels relative to your capture point. The analysis runs once per packet in capture order, so the same loss looks different from client side, server side, or mid-path. Wireshark even offers a preference to let fast retransmission supersede the out-of-order interpretation in ambiguous cases [206].
Zero Window and Window Updates
The 16-bit window field in every TCP header advertises how many bytes the receiver can still accept, the free space in its receive buffer, once the field’s value is multiplied by the scale factor negotiated in the handshake [206, 210]. Zero window is the receiver advertising zero, telling the sender “do not send, my buffer is full.” The sender must pause until a window update reopens [209, 206]. Some zero windows are normal. A printer may zero its window while reversing a sheet, but in general a zero window means the receiving application is not draining the socket buffer fast enough, a resource or capacity problem on that host [206, 219].
Because the zero window can evaporate while the pause lasts, TCP probes it. The sender transmits one byte, a ZeroWindowProbe (look for tcp.analysis.zero_window_probe), to elicit an ACK, doubling its persist timer if the window stays closed [209, 220]. Receiving data anyway after advertising zero is a ZeroWindowViolation, and a useful accusation of a misbehaving sender [209]. When the application finally consumes bytes, the receiver sends a pure WindowUpdate advertising the reopened space, typically the packet you see just before the data resumes [209].
The mirror-image label is WindowFull, set on a segment whose payload exactly fills the receiver’s advertised window. After that segment, the sender must stop until ACKs advance. Unlike a zero window, this occurs without any receiver complaint, whenever the window is too small for the round-trip path, the classic small-buffer-on-high-latency case [209, 221]. Filter both conditions together with tcp.analysis.window_full or tcp.analysis.zero_window.
Then separate them with tcp.window_size == 0, which isolates the zero-window advertisements, a receiver-side verdict. What remains are Window Full segments from the sender [222, 210]. Window scaling deserves its own check. When it was not negotiated in the SYN exchange, both sides are stuck with a 64 KB ceiling regardless of bandwidth-delay product [210]. The TCP Stream Graphs > Window Scaling plot makes the story visual. A flat bytes-out line under a falling receive-window line is the receiver throttling the sender [223].
The Expert-Info View
Analyze > Expert Information condenses the file’s anomalies into one table grouped by severity (chat, notes, warnings, and errors) alongside the packet numbers, and clicking an entry jumps your packet list to the frame [224, 225]. Sort by severity, Errors first, for a health summary in one screen. Out-of-order segments and resets warn, retransmissions and duplicate ACKs note [225, 138]. On the command line, tshark -r capture.pcap -q -z expert prints the same grouping with occurrence counts [225, 159].
Two cautions, both from Wireshark’s own documentation. Expert information is a hint, not a diagnosis. Its presence does not prove a problem, and its absence does not prove health [224]. The counts are only as good as the capture, because the same analysis that mislabels a duplicated capture frame as a retransmission also inflates the expert table [208]. Use the dialog to find candidate packets. Right-click an item to Prepare a Filter from it, which yields tcp.analysis.* conditions you can reuse. tcp.analysis.flags alone selects every packet with any TCP-analysis annotation, and it is the basis of Wireshark’s “Bad TCP” coloring rule [225, 138].
Attributing the Cause: Client, Network, or Server
Now connect the labels into a verdict. A methodical sequence works. State the complaint in plain language, map it to a host and time, check Conversations and Endpoints for the busy flows, review Expert Information, form one hypothesis, and test it against the packets before moving on [53]. The filter combinations below are the hypotheses.
- Network-path loss. When
tcp.analysis.retransmissionappears withouttcp.analysis.window_full, the receiver has buffer headroom and keeps up, yet segments must be resent. Look for dup-ACK/fast-retransmit pairs, then suspect congestion, a lossy link, or duplex mismatch on the path [210]. - Receiver/application bottleneck. When
tcp.analysis.zero_windowortcp.analysis.window_fullshows up, the receiver cannot drain its socket. Correlate with that host’s CPU, disk, andrecv()activity. Increasing buffers merely hides the slowness [219, 226]. - Sender- or path-severity problem. When
tcp.analysis.retransmissionappears withouttcp.analysis.fast_retransmission, the sender waited out full RTOs. Too few segments may have followed the loss to generate three duplicate ACKs (tail loss, small windows). Otherwise, suspect ACK loss, a broken return path, or very severe loss [210].
Always test both directions. Loss is often asymmetric, and capturing only one side of a conversation hides which ACKs actually arrived [140]. Also check where you captured. “Previous segment not captured” may mean your monitor port is oversubscribed rather than that the network lost bytes [227, 140]. One capture rarely proves where a packet was lost. Sender- and receiver-side captures (or captures from both ends of the conversation) together separate an on-wire drop from a late or duplicated copy [200]. These labels are not TCP header fields but Wireshark’s reading of the stream [206], so filter tcp.analysis.retransmission and tcp.analysis.zero_window in each direction and confirm each label against the sequence numbers before you name the cause.
Exercises
Open
lab/tcp-ecn-sample.pcapand read the handshake and the first request. What is the connection’s initial RTT as Wireshark records it? The GET in frame 4 carries 161 bytes starting at relative sequence 1: predict the acknowledgement number the server’s next segment will carry, then predict the client’s ACK for the server’s first 256-byte reply. Check both against frames 5 and 6.In
lab/dns-remoteshell.pcap, filter ontcp.port == 21. You’ll see SYNs labelled[TCP Retransmission]and[TCP Port numbers reused], and every answer is[RST, ACK]. How many connection attempts did the client really make, what did the server say to each, and why do neither of those two labels mean what they seem to? Usetcp.completenessto classify the connections.lab/http2-data-reassembly.pcapis a fast HTTPS download with exactly one[TCP Retransmission], at frame 38. Was any data lost? Read the sequence numbers of frames 37 and 38, then the acknowledgement and SACK fields of frame 39, and explain what they prove. Also say what the[RST, ACK]in the last frame means for this connection.lab/tcp-ecn-sample.pcapmoves about 83 kB in about 94 seconds, and the expert summary shows no retransmissions, no zero windows, and no Window Full. Attribute the slowness to the client, the network, or the server. Compare the most data the server ever had in flight with the smallest window the client advertised, and look for TCP and IP flags beyond the ones this chapter names.