How Reliable Transport Works: ARQ, Sliding Windows, Flow Control and Timeouts
The ideas every reliable transport is built from: acknowledgments, sequence numbers and retransmission (ARQ), why stop-and-wait is slow, how sliding windows fill a path, go-back-N versus selective repeat, flow and congestion control, and choosing a retransmission timeout.
kvi5hnuCode Sprout team member15 min readOn this page
IP delivers packets on a best-effort basis. Along a path of several links and routers, a packet can be lost, damaged, duplicated, delayed or delivered out of order. Yet applications such as web browsers, databases and file transfers need every byte, exactly once, in the right order. Turning an unreliable packet service into a reliable one is the job of a reliable transport, and TCP is the most important one. QUIC (article 86), which carries HTTP/3, applies the same ideas over UDP.
Before looking at TCP itself, this article builds the ideas TCP is made from, one at a time, and measures them in the course lab with a small toy protocol. Every later article in Parts 10 and 11 is a refinement of something here.
Two ways to handle errors
There are two broad strategies for errors on a channel:
- Forward error correction (FEC) adds redundant bits so the receiver can repair some damage on its own, without asking for anything again. It's used heavily on the physical layer (Wi-Fi, mobile and fiber links all use error-correcting codes) and by some real-time media applications, where waiting for a retransmission would take too long.
- Detect and resend. The receiver only needs to detect damage, which takes far fewer bits than correcting it: a checksum or CRC (cyclic redundancy check, a stronger checksum used by link layers such as Ethernet) catches nearly all corruption. A damaged packet is thrown away, and the sender sends it again. This is the approach of TCP, and it's called ARQ (automatic repeat request).
Over a path of many links, detection plus resending has a further advantage: it also handles problems that no code can fix, such as a router dropping a packet because its queue was full.
The basic ARQ toolkit
The simplest ARQ protocol needs three mechanisms.
- Acknowledgments (ACKs). When the receiver gets a packet intact, it tells the sender. If the packet is damaged, the receiver says nothing.
- A retransmission timer. After sending, the sender waits. If no ACK arrives in time, it assumes the packet was lost and sends it again.
- Sequence numbers. If the ACK, not the packet, was lost, the sender can't tell the difference and resends anyway. The receiver then gets a second copy. A sequence number in each packet lets the receiver recognize the duplicate, discard it and ACK it again.
These three are enough for correctness. With one packet outstanding at a time, the protocol is called stop-and-wait: send a packet, wait for its ACK, send the next one.
Why stop-and-wait is slow
Stop-and-wait sends one packet per round trip. If the round-trip time (RTT) is 40 ms and each packet carries 1000 bytes, the best possible rate is 1000 × 8 bits / 0.04 s = 200 kbit/s, no matter how fast the links are. The rest of the time, the sender sits idle waiting for an ACK.
The fix is to allow several packets in flight at once. A sender with a window of W packets may send up to W packets before it has heard an ACK for the first of them. The ideal rate becomes:
until it reaches the capacity of the slowest link on the path.
The diagram below shows the difference on a 40 ms round trip.

Measuring it: a toy sliding-window protocol
To see the formula work, the course lab ran a tiny ARQ protocol written in Python over UDP. The sender numbers 1000-byte packets, keeps at most W of them unacknowledged, and resends from the oldest unacknowledged packet if no progress is made for 0.5 seconds. The receiver accepts packets only in order and answers each one with a cumulative ACK: the number of the next packet it expects.
The path from client (192.0.2.10) to server (198.51.100.10) had 20 ms of delay in each direction and a 20 Mbit/s bottleneck. First, the round-trip time the protocol has to live with:
rtt min/avg/max/mdev = 45.104/62.794/97.027/24.210 ms
Only three pings were sent. The minimum, 45 ms, is the 40 ms of added delay plus a few milliseconds of lab overhead. The maximum, 97 ms, pulls the average up: the first ping of a run is usually slower because the hosts still have to resolve addresses with ARP (article 21). mdev is how much the samples vary. Then one transfer per window size, from stop-and-wait (W = 1) to W = 256. Each line shows the window, how many packets were delivered, how long it took, the resulting rate, and how many packets were sent in total and resent:
window 1: 100 packets in 4.61 s = 0.17 Mbit/s (sent 100, resent 0)
window 2: 100 packets in 2.40 s = 0.33 Mbit/s (sent 100, resent 0)
window 4: 100 packets in 1.24 s = 0.65 Mbit/s (sent 100, resent 0)
window 8: 100 packets in 0.62 s = 1.28 Mbit/s (sent 100, resent 0)
window 16: 192 packets in 0.56 s = 2.74 Mbit/s (sent 192, resent 0)
window 32: 384 packets in 0.55 s = 5.60 Mbit/s (sent 384, resent 0)
window 64: 768 packets in 0.55 s = 11.17 Mbit/s (sent 768, resent 0)
window 128: 1536 packets in 0.68 s = 18.03 Mbit/s (sent 1536, resent 0)
window 256: 3072 packets in 1.32 s = 18.58 Mbit/s (sent 3072, resent 0)

The chart above plots the same numbers, with the formula as a dashed line. The measurements follow the formula closely:
- Stop-and-wait moved 100 packets in about 4.6 seconds, roughly one round trip each: 0.17 Mbit/s on a 20 Mbit/s path.
- Each doubling of the window doubled the rate, as long as the window was smaller than what the path can hold.
- Past about 100 packets, the rate stopped growing. The path holds 20 Mbit/s × 0.04 s = 800,000 bits = 100,000 bytes, which is 100 of these packets. That amount is the bandwidth-delay product (BDP). A window larger than the BDP can't make the link any faster. The extra packets just wait in the router's queue and make the delay longer.
The measured points sit a little below the dashed line because each run is short, only about 12 round trips, and the first round trip has nothing to ACK yet.
Sliding windows
As ACKs arrive, the window moves along the data, which is why it's called a sliding window. At any moment the sender's data falls into four groups, shown in the diagram:

- Sent and acknowledged. Finished. The sender can free these buffers.
- Sent, not yet acknowledged. The sender must keep a copy in case it has to resend.
- Not sent, but inside the window. Can go now.
- Outside the window. Must wait.
When an ACK covers the oldest outstanding packet, the left edge of the window moves right (the window closes), and the right edge moves right too (the window opens), so new data can be sent. The receiver keeps a similar window: the range of sequence numbers it's willing to accept and buffer.
Go-back-N and selective repeat
Windows make loss recovery harder, because when one packet is lost, many after it are already on the way. There are two classic answers.
- Go-back-N. The receiver accepts only the next packet in order and discards anything after a gap. On a timeout, the sender resends the lost packet and every packet after it. It's simple, and the receiver needs no buffer for out-of-order data, but one loss can cost a whole window of resends.
- Selective repeat. The receiver buffers packets that arrive after a gap and tells the sender exactly what it has. The sender resends only the missing packets.
The toy protocol above is go-back-N. Here it is again with 1% random loss added at the bottleneck:
window 8: 100 packets in 0.67 s = 1.19 Mbit/s (sent 100, resent 0)
window 32: 384 packets in 2.93 s = 1.05 Mbit/s (sent 512, resent 128)
window 128: 1536 packets in 11.42 s = 1.08 Mbit/s (sent 3840, resent 2304)
With a 128-packet window, the sender transmitted 3840 packets to deliver 1536, and every loss stalled it for the 0.5-second timeout. The rate fell from about 18 Mbit/s to about 1 Mbit/s. That's why real protocols don't stop at go-back-N:
- TCP's receiver keeps out-of-order data, and the selective acknowledgment (SACK) option tells the sender exactly which blocks arrived. Article 66 covers this.
- TCP detects most losses without waiting for a timer, using duplicate ACKs and timing (fast retransmit and RACK, also in article 66).
- TCP also slows down when it sees loss, because loss usually means a queue somewhere is full. That's congestion control.
Variable windows: flow control and congestion control
A fixed window has two problems. The receiver might be slow, and the network between the two ends might be slow. Both are handled by changing the window's size over time.
Flow control protects the receiver. The receiver tells the sender how much buffer space it has left, and the sender never sends more than that. This message is a window advertisement (or window update), and in TCP it rides in every segment's header next to the ACK. This is window-based flow control. The alternative, rate-based flow control, gives a sender a fixed rate. It suits streaming and multicast, where there's no per-receiver feedback loop.
Congestion control protects the network. Routers along the path have limited queues, and a sender that pushes faster than the bottleneck can carry will fill a queue and cause drops for everyone. The receiver's advertisement can't help here: it knows nothing about router queues. So the sender keeps a second limit, the congestion window, and adjusts it based on what it observes:
- Implicit signals, which the sender has to infer: packet loss, or a rising RTT.
- Explicit signals: routers can mark packets with ECN (article 25) instead of dropping them.
TCP's sending window at any time is the smaller of the receiver's advertised window and its own congestion window. Part 12 is entirely about congestion control.
Setting the retransmission timeout
How long should the sender wait before deciding a packet is lost? The wait must cover the whole round trip: transmission, the path in both directions, and processing at the receiver. None of those is known in advance, and they change as load changes.
- Too short a timeout causes spurious retransmissions: packets that weren't lost are sent again, wasting capacity, and with TCP also needlessly cutting the sending rate.
- Too long a timeout leaves the connection idle after a real loss, as the lossy run above showed.
So the sender measures round-trip times and estimates both their average and how much they vary. The timeout is set somewhat above the average, by a margin that grows with the variation. In principle, a path with a steady 40 ms RTT could use a timeout close to 40 ms (real TCPs add a minimum, 200 ms on Linux). A path whose RTT jumps between 40 and 200 ms needs a much longer one. Article 64 shows exactly how TCP does this, measured live.
How these pieces appear in TCP
| Idea | In TCP |
|---|---|
| Sequence numbers | Number every byte, not every packet (32-bit Sequence Number field) |
| ACKs | Cumulative: the next byte expected; plus SACK blocks for out-of-order data |
| Window | Receive window advertised in every segment, with window scaling for large values |
| Retransmission timer | One per connection, set from measured RTT: the RTO, retransmission timeout (article 64) |
| Loss detection without timers | Duplicate ACKs, SACK, RACK-TLP, a time-based loss detector (article 66) |
| Congestion control | Congestion window, slow start, CUBIC (Linux's default algorithm) and others (Part 12) |
| Error detection | 16-bit checksum over header, data and a pseudo-header of IP addresses (article 45) |
Common questions
Why not just use error-correcting codes and never retransmit?
Codes can repair a limited number of damaged bits, but they can't recover a packet that never arrived, and on the Internet most loss is whole packets dropped by full queues. Strong codes also cost extra bandwidth on every packet, even when nothing goes wrong. Detect-and-resend pays only when loss actually happens.
If the ACK is lost, how does the receiver avoid delivering the data twice?
The sender times out and resends, and the receiver sees a sequence number it has already accepted. It discards the copy and ACKs again, which tells the sender to move on.
Is a bigger window always better?
No. Up to the bandwidth-delay product, a bigger window means more throughput. Beyond it, the extra data just sits in router queues, adding delay for every flow through that router, and eventually causing drops. Congestion control exists to keep the window near the useful size.
What's the difference between flow control and congestion control?
Flow control keeps a fast sender from overrunning a slow receiver, and the receiver tells the sender its limit explicitly. Congestion control keeps senders from overrunning the network, and the sender has to infer the limit from loss, delay or ECN marks.
Why does TCP count bytes instead of packets?
Because TCP is a byte stream. A retransmission may carry more or less data than the original segment (article 67 calls this repacketization), and byte numbering lets the receiver match data precisely whatever the segment sizes.
What does "in flight" mean?
Data the sender has transmitted but for which it hasn't yet received an acknowledgment. It's either in the network or at the receiver with its ACK still on the way back.
Summary
- Reliable transport over IP uses ARQ: detect errors with a checksum, acknowledge good packets, resend on timeout, and use sequence numbers to discard duplicates.
- Stop-and-wait sends one packet per round trip, which was 0.17 Mbit/s on a 20 Mbit/s, 40 ms lab path.
- A sliding window keeps W packets in flight. Throughput is about W × packet size / RTT until the window reaches the bandwidth-delay product, as the lab graph showed.
- Go-back-N resends everything after a loss; selective repeat resends only what's missing. With 1% loss, the toy go-back-N fell from 18 to about 1 Mbit/s.
- Flow control (receiver's advertised window) protects the receiver; congestion control (sender's congestion window) protects the network.
- The retransmission timeout must be estimated from measured RTTs: too short causes spurious resends, too long wastes time after real loss.
Practice questions
1. A path has a 60 ms RTT, and a stop-and-wait protocol sends 1500-byte packets. What's the best possible throughput?
Answer
One packet per round trip: 1500 × 8 bits / 0.060 s = 200,000 bit/s, or 200 kbit/s, regardless of link speed.
2. What window, in bytes, is needed to fill a 100 Mbit/s path with an 80 ms RTT?
Answer
The bandwidth-delay product: 100,000,000 bit/s × 0.080 s = 8,000,000 bits = 1,000,000 bytes, about 1 MB.
3. In the lab, why did going from a window of 128 to 256 packets barely change the throughput?
Answer
The path's bandwidth-delay product was about 100 packets (20 Mbit/s × 40 ms = 100,000 bytes). Once the window exceeds that, the link is already full. The extra packets wait in the router's queue, adding delay without adding throughput.
4. Packet 5 of a window of 10 is lost. Under go-back-N, which packets are sent again? Under selective repeat?
Answer
Go-back-N resends packet 5 and everything sent after it, packets 6 to 10, because the receiver discarded them. Selective repeat resends only packet 5, because the receiver kept 6 to 10 in its buffer.
5. A receiver's application stops reading. Which mechanism stops the sender, and how does the sender learn about it?
Answer
Flow control. As the receiver's buffer fills, it advertises a smaller and smaller window in its ACKs, eventually zero. The sender may not send beyond the advertised window, so it stops. Article 69 shows TCP's zero window in a real capture.
6. Why is the retransmission timeout set above the average RTT and not equal to it?
Answer
About half of RTT samples are above the average, so a timeout equal to the average would fire for many packets that weren't lost, causing spurious retransmissions. The timeout adds a margin based on how much the RTT varies.
Previous: Troubleshooting DNS With dig: Following a Resolution Step by Step
Next: TCP's Service Model and Header: Segments, Sequence Numbers and Flags

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.