Sub topic 6
Reliable delivery: timeouts, retransmission, and fast retransmit
This chapter assumes you know the TCP segment fields (sequence number, acknowledgement number, flags), the three-way handshake, and the terms RTT and bandwidth. IP can drop, duplicate, delay, and reorder packets. TCP builds a reliable, in-order byte stream on top of it. It does this with cumulative acknowledgements, a retransmission timer, a sliding window, and a shortcut called fast retransmit.
What TCP must guarantee
TCP gives the application a byte stream that has these properties:
- Every byte sent arrives, unless the connection fails.
- Bytes arrive in the order they were sent.
- Each byte is delivered once, with duplicates discarded.
The sender cannot see the network. It can only observe acknowledgements (ACKs) and the passage of time. Every recovery rule in this chapter is built from those two signals.
Cumulative acknowledgements
TCP numbers bytes, not segments. The acknowledgement number is the sequence number of the next byte the receiver expects. It confirms that all earlier bytes arrived.
Suppose the sender transmits segments of 100 bytes with sequence numbers 1000, 1100, 1200, and 1300.
| Segment arriving at receiver | Receiver's state | ACK sent |
|---|---|---|
| seq 1000 (bytes 1000-1099) | in order | 1100 |
| seq 1100 | in order | 1200 |
| seq 1200 is lost; seq 1300 arrives | gap at 1200 | 1200 (duplicate) |
| seq 1400 arrives | gap at 1200 | 1200 (duplicate) |
| seq 1200 retransmitted arrives | gap filled, if 1300 and 1400 were buffered | 1500 |
Three points follow from this table:
- An ACK of 1200 says nothing about 1300 and 1400, even though they were received. Standard cumulative ACKs cannot report out-of-order data. (The optional SACK extension can.)
- An out-of-order segment makes the receiver send an immediate duplicate ACK: another ACK with the same number as before.
- One ACK can cover many segments. The last row acknowledges three segments at once.
A common GATE trap: the ACK number is last byte received plus one, not the sequence number of the last segment received.
The retransmission timer
If an ACK for a segment does not arrive in time, the sender retransmits it. The time limit is the retransmission timeout (RTO). Choosing it is a trade-off:
- Too short: the sender retransmits segments that were only delayed, wasting bandwidth.
- Too long: the sender idles after a real loss, and throughput drops.
The right value depends on the RTT, which changes over time. TCP therefore measures RTT continuously and adapts.
Estimating RTT
TCP measures SampleRTT, the time from sending a segment to receiving its ACK. A single sample is noisy, so TCP smooths it with an exponentially weighted moving average (EWMA):
- EstimatedRTT = (1 - α) × EstimatedRTT + α × SampleRTT, with α = 1/8
- DevRTT = (1 - β) × DevRTT + β × |SampleRTT - EstimatedRTT|, with β = 1/4
- RTO = EstimatedRTT + 4 × DevRTT
DevRTT tracks how much the samples vary. A network with jittery RTTs gets a larger safety margin.
The following program applies these formulas to a series of samples.
ALPHA = 1 / 8
BETA = 1 / 4
def rto_trace(samples, est=None, dev=None):
for i, sample in enumerate(samples, start=1):
if est is None:
est, dev = sample, sample / 2 # first-sample initialisation
else:
dev = (1 - BETA) * dev + BETA * abs(sample - est)
est = (1 - ALPHA) * est + ALPHA * sample
rto = est + 4 * dev
print(f"sample {i}: SampleRTT={sample:6.1f} "
f"Est={est:6.1f} Dev={dev:5.1f} RTO={rto:6.1f}")
rto_trace([100, 120, 90, 300, 110])The order of the two updates matters. This code updates DevRTT using the old EstimatedRTT, which is the order in RFC 6298. Some textbook exercises update EstimatedRTT first. Follow the order the question states.
Notice what the 300 ms sample does. EstimatedRTT moves only a little, since α is small, but DevRTT jumps. The RTO widens quickly, which is the intended behavior.
Karn's algorithm
Suppose a segment is retransmitted and then an ACK arrives. The sender cannot tell whether the ACK answers the original or the retransmission. A wrong guess gives a badly skewed SampleRTT.
Karn's algorithm avoids the problem: do not take RTT samples from retransmitted segments. Only segments sent exactly once contribute.
Exponential backoff
When the timer expires, TCP retransmits the oldest unacknowledged segment and doubles the RTO for the next attempt. For example, 1 s becomes 2 s, then 4 s, then 8 s. The doubling stays in effect until a fresh ACK for new data arrives. Backoff matters because a timeout often means the network is congested, and retrying faster would make that worse.
Timers run on one segment
TCP does not keep a separate timer for every segment. The standard model keeps one timer for the oldest unacknowledged segment. When an ACK advances the left edge of the window, the timer restarts for the next oldest unacknowledged segment. When the timer fires, only that one segment is retransmitted. This differs from Go-Back-N, which resends the whole window, and from Selective Repeat, which keeps a timer per packet. TCP is best described as a hybrid: cumulative ACKs like Go-Back-N, and single-segment retransmission and receiver buffering like Selective Repeat.
Fast retransmit
Waiting for the RTO is slow, because the RTO is usually several RTTs long. A loss in the middle of a window produces duplicate ACKs well before the timer fires. TCP uses them as an early warning.
Fast retransmit: when the sender receives three duplicate ACKs (four ACKs in total with the same number), it retransmits the missing segment immediately, without waiting for the timeout.
Why three? One or two duplicates can come from simple reordering in the network. Three duplicates make a real loss much more likely.
In the diagram the first ACK of 1200 is a normal one if segment 1100 was received. To keep the count straight, note this precisely: the ACK that first carries the number 1200 is the original, and each repeat after it is a duplicate. The diagram abbreviates the earlier exchange for space, so treat it as showing the pattern, not an exact byte-for-byte trace.
After the retransmission arrives, the receiver already holds 1300, 1400, and 1500. Its next ACK jumps to 1600, which covers all of them. That is why one fast retransmit can repair a loss without resending the later segments.
Fast retransmit versus timeout
| Aspect | Timeout | Fast retransmit |
|---|---|---|
| Trigger | RTO expires | 3 duplicate ACKs |
| What it implies | Possibly severe loss: no ACKs coming back | Mild loss: later segments are still getting through |
| Cost | Idle time of one RTO | About one RTT |
| Congestion response (next chapters) | Tahoe and Reno: cwnd drops to 1 MSS | Tahoe: cwnd drops to 1 MSS; Reno: halves cwnd |
The last row anticipates congestion control. For now, the point is that the two events are treated differently because they carry different information about the network.
Limits of fast retransmit
Fast retransmit needs enough segments in flight after the loss to generate three duplicates. It fails to trigger when:
- The window is small, for example fewer than four segments, so too few segments follow the lost one.
- The lost segment is near the end of the transfer, with nothing after it.
- Several segments from one window are lost, which reduces the number of duplicate ACKs.
- ACKs themselves are lost, which removes some duplicates.
In those cases the RTO is the fallback. This is also why the timer cannot be removed from the design.
Another edge case: if the ACK number does not advance but the segment carries data, a window update, or a different window size, it is not counted as a duplicate ACK. A pure duplicate has the same ACK number, no data, no window change, and no SYN or FIN flag.
Retransmissions and the sliding window
Reliability and throughput are linked. The sender may have many unacknowledged segments in flight, up to the window size. Two consequences follow:
- With a window of W segments, a loss stalls the left edge of the window until the missing segment is repaired. Later ACKs cannot advance past the hole.
- Fast retransmit shortens that stall from about one RTO to about one RTT, so the window keeps moving.
The effective window and throughput calculations come in a later chapter. Here the key point is that retransmission policy directly affects how much of the window is usable.
Common errors
- Writing the ACK number as the last byte received, not the next byte expected.
- Counting the original ACK as one of the three duplicates. Three duplicates means the fourth ACK with the same number.
- Using SampleRTT from a retransmitted segment, which Karn's algorithm forbids.
- Forgetting that RTO doubles on each consecutive timeout.
- Assuming TCP resends the whole window after a loss. It resends the oldest missing segment, and later segments are resent only if they are also found missing.
- Computing RTO as EstimatedRTT alone. The deviation term is part of the formula.
Worked example
A sender has EstimatedRTT = 100 ms and DevRTT = 20 ms. A new sample of 140 ms arrives. Use α = 1/8 and β = 1/4, updating DevRTT first.
- DevRTT = 0.75 × 20 + 0.25 × |140 - 100| = 15 + 10 = 25 ms.
- EstimatedRTT = 0.875 × 100 + 0.125 × 140 = 87.5 + 17.5 = 105 ms.
- RTO = 105 + 4 × 25 = 205 ms.
Now the segment times out. The next RTO is 2 × 205 = 410 ms, and a second consecutive timeout gives 820 ms.
Exercise
A receiver has received bytes 0-499 and 600-899, and bytes 500-599 are missing. It then receives bytes 900-999. What ACK number does it send, and after how many such duplicate ACKs (counting from the first ACK of 500) does the sender fast-retransmit?
Show answer
The ACK number is 500, the next byte the receiver expects, because the gap at 500-599 blocks everything after it. The first ACK of 500 is the original and the sender retransmits on the third duplicate, which is the fourth ACK carrying 500. The sender then resends the segment starting at byte 500.
Exercise
With EstimatedRTT = 200 ms and DevRTT = 10 ms, the RTO is 240 ms. A segment times out twice in a row before a fresh ACK arrives. What is the RTO used for the third transmission attempt, and why should the RTT of the eventual ACK not be used as a sample?
Show answer
The RTO doubles after each timeout: 240 ms, then 480 ms for the second retransmission, then 960 ms for the third. The ACK's RTT is not sampled because the segment was retransmitted, so the sender cannot tell which transmission the ACK answers. Karn's algorithm excludes such samples.
Exercise
Why does fast retransmit often fail to trigger when the congestion window is only 3 segments and the first segment of the window is lost?
Show answer
Only two segments follow the lost one, so the receiver can send at most two duplicate ACKs. Fast retransmit needs three, so the sender must wait for the RTO to expire.