The RFC 6298 retransmission timer step by step: first sample, smoothed estimates, the 1 second floor, doubling on expiry and Karn's rule, traced over a synthetic delay spike.
The timer behind every lost packet
When a TCP sender transmits a segment, it starts a timer. If the acknowledgement does not arrive before the timer expires, the sender assumes the segment was lost and sends it again. Everything about that timer is a compromise. Too short, and the sender retransmits segments that were only delayed, wasting capacity on a path that is already slow. Too long, and a real loss stalls the connection for a noticeable time.
RFC 6298, published in June 2011, specifies how a TCP sender computes that retransmission timeout, the RTO. It is short, and every rule in it exists for a reason. This guide implements it step by step, traces it over synthetic round-trip times with a delay spike, and shows where Karn's rule and exponential backoff come in. The companion code is a small estimator with tests for each rule; it does not open a socket.
Two estimates and a margin
The RTO is built from two running estimates, updated from round-trip time measurements, R:
- SRTT, the smoothed round-trip time, an exponentially weighted moving average of R;
- RTTVAR, the round-trip time variation, an exponentially weighted moving average of how far each R lies from SRTT.
The timeout is the smoothed estimate plus a margin of four times the variation: RTO = SRTT + max(G, K × RTTVAR), with K = 4 and G the clock granularity. A path with stable delay has a small RTTVAR and an RTO close to SRTT. A path with jittery delay gets a wider margin, so ordinary jitter does not trigger retransmissions.
The rules, in the RFC's numbering:
- Before any measurement, RTO is 1 second (rule 2.1). An earlier specification, RFC 2988, used 3 seconds.
- On the first measurement R: SRTT = R, RTTVAR = R / 2 (rule 2.2).
- On each later measurement: first RTTVAR = (1 - beta) × RTTVAR + beta × |SRTT - R|, then SRTT = (1 - alpha) × SRTT + alpha × R, with alpha = 1/8 and beta = 1/4 (rule 2.3).
- Whenever RTO is computed and is less than 1 second, it should be rounded up to 1 second (rule 2.4).
- A maximum may be placed on RTO, provided it is at least 60 seconds (rule 2.5).
The order in step 3 matters. RTTVAR is updated with the old SRTT, before SRTT absorbs the new sample. Swapping the two lines gives a smaller variation after a jump, because the new SRTT is already closer to R, and so a timer that is slower to widen. The companion code has a test for exactly that.
if self.srtt is None:
self.srtt, self.rttvar = r, r / 2 # rule 2.2
else:
self.rttvar = (1 - BETA) * self.rttvar + BETA * abs(self.srtt - r) # rule 2.3, first
self.srtt = (1 - ALPHA) * self.srtt + ALPHA * r # then SRTT
raw = self.srtt + max(self.granularity, K * self.rttvar)
self.rto = self._clamp(raw)A trace with a delay spike
The example feeds the estimator a synthetic series: eight samples of 100 ms, a spike of 400, 420 and 380 ms, then six more samples of 100 ms. The clock granularity is 1 ms.
With the 1 second floor the RFC recommends, the RTO is 1.000 s for every sample. The formulas move underneath, but the floor hides them: on a 100 ms path, nothing the estimator computes comes close to a second.
To see the formulas, the example also runs with an illustrative floor of 0.2 s. That is not what RFC 6298 recommends; it is there only to make the arithmetic visible.
sample 0.100s -> SRTT 0.1000 RTTVAR 0.0067 raw 0.1267 RTO 0.200
sample 0.400s -> SRTT 0.1375 RTTVAR 0.0800 raw 0.4575 RTO 0.458
sample 0.420s -> SRTT 0.1728 RTTVAR 0.1306 raw 0.6953 RTO 0.695
sample 0.380s -> SRTT 0.1987 RTTVAR 0.1498 raw 0.7978 RTO 0.798
sample 0.100s -> SRTT 0.1864 RTTVAR 0.1370 raw 0.7344 RTO 0.734Before the spike, eight identical samples have shrunk RTTVAR to under 7 ms, so the raw RTO is about 127 ms. The first 400 ms sample moves SRTT only to 137.5 ms, because alpha is 1/8, but RTTVAR jumps to 80 ms and the margin of four times RTTVAR lifts the RTO to 458 ms. That is the design working: the variation term reacts quickly and protects the sender from treating a sudden delay as a loss, while SRTT moves slowly. By the third spike sample the RTO is 798 ms, about twice the new delay. After the spike, RTTVAR decays by a quarter each sample, and the RTO comes down over several round trips.
The same shape on a longer path, 300 ms rising to 900 ms, does cross the floor: the RTO peaks at 1.703 s on the third spike sample and is back to 1.031 s after six normal samples.
The floor in rule 2.4 is a "should", and the RFC is explicit about the reason: a conservative minimum avoids spurious retransmissions on paths with delayed acknowledgements and variable delay. Some operating systems use a lower minimum on low-latency networks; whatever yours does, read its documentation rather than assuming the RFC value.
Exponential backoff
When the timer expires, the sender retransmits the earliest unacknowledged segment and doubles the RTO (rule 5.5), up to the maximum. Starting from the initial 1 second with a 60 second cap, successive expiries give 1, 2, 4, 8, 16, 32, 60 and 60 seconds.
The backed-off value stays in force until a new valid measurement arrives. That matters for the next rule, because after a retransmission the next acknowledgement is ambiguous.
The RFC also has a special case for connection setup. If the SYN itself had to be retransmitted and the RTO in use is less than 3 seconds, the RTO must be re-initialised to 3 seconds when data transmission begins (rule 5.7). A handshake that needed a retransmission suggests a difficult path, and the first data segments should not be timed aggressively.
The Karn rule for ambiguous samples
Suppose a segment is sent at time 0, the timer expires at 1.0 s and the segment is retransmitted, and an acknowledgement arrives at 1.25 s. Was it for the original, giving an RTT of 1.25 s, or for the copy, giving 0.25 s? The sender cannot tell. Karn and Partridge pointed this out in 1987, and RFC 6298 adopts their answer: do not take RTT samples from segments that were retransmitted, unless the timestamps option makes the measurement unambiguous.
The example shows why. Two estimators start from one 100 ms sample with a 0.2 s floor, so RTO is 0.3 s, and then both time out and back off to 0.6 s. The careful estimator discards the ambiguous 0.25 s sample and keeps 0.6 s until a clean measurement arrives. The naive one takes the 0.25 s sample as if the copy had been acknowledged, and drops its RTO to 0.419 s. If the original segment really did take 1.25 s, the naive sender has just set a timer that is guaranteed to fire again, and it will keep retransmitting into a slow path.
With the TCP timestamps option, defined in RFC 7323, each acknowledgement echoes the timestamp of the segment that triggered it, so the sender knows which transmission it is measuring. That is what the timestamps flag in the companion code models.
Failure modes in practice
A floor that is too low causes spurious retransmissions, which in turn can trigger congestion responses that slow the connection down for no reason. A floor that is too high makes losses on a fast local network expensive: a 1 second stall on a path with a 1 ms round trip is a thousand round trips of nothing.
Ignoring Karn's rule after a loss collapses the timer on exactly the paths where it needs to be generous.
Very long backoff chains can leave a connection apparently hung for minutes. The RFC allows an implementation to clear SRTT and RTTVAR after several backoffs, so that the next measurement starts fresh rather than being averaged with an estimate taken before the path changed.
Application timeouts interact with all of this. An HTTP client with a 2 second request timeout on a path whose RTO has backed off to 4 seconds will give up before TCP has retransmitted even once.
Verification
The companion code has seven tests: the initial RTO and first-sample rule, the update order using the old SRTT, the floor hiding a short-path spike, a long-path spike lifting the RTO above the floor, doubling and capping on expiry, Karn discarding ambiguous samples, and the 3 second rule after a lost SYN. Run python -m unittest -v. The RTT series are synthetic and nothing is sent over a network.
Run the example yourself
The RFC 6298 estimator, the spike traces, backoff, Karn and the SYN rule, with seven tests. Companion code on GitHub; its README lists the prerequisites, exact commands, expected output and limits.