TCP congestion control
Describe slow start, congestion avoidance and modern algorithms like CUBIC and BBR.
By Invicly Tech, , in Computer Networking. About 12 minutes to read.
In short
Congestion control protects the network itself by limiting how much a sender has in flight. TCP grows a congestion window quickly during slow start, then cautiously during congestion avoidance, and cuts it back when it detects loss. Modern variants such as CUBIC and BBR tune this for fast, long-distance links.
Explained simply
Flow control protects the receiver. But the path in between, full of routers with limited queues, can overflow too. If every sender went as fast as it could, queues would fill, packets would drop, everyone would resend, and the network would carry almost nothing useful. This really happened on the early internet in 1986 and is called congestion collapse.
So each TCP sender keeps a private limit called the congestion window (cwnd). It is not in any header; it is the sender's own guess of how much data the network can hold. At any moment, the data in flight is limited by the smaller of cwnd and the receiver's window.
TCP starts small and grows fast. In slow start, a new connection begins with about 10 segments and doubles each round trip. After a threshold, it grows by only about one segment per round trip. When it sees loss, it cuts back. It is like a driver slowly pushing the speed up until feeling the bumps.
There are several recipes for this. Reno is the classic. CUBIC is the default on Linux and on modern Windows. BBR, from Google, measures the path's bandwidth and delay instead of waiting for loss. The choice matters most on long, fast or lossy links.
Press Play on a diagram to walk through it one step at a time.
- 1Slow start
cwnd doubles each RTT.
- 2Threshold reached
Switch to linear growth.
- 3Congestion avoidance
About +1 segment per RTT.
- 4Loss detected
Halve cwnd (fast recovery) or reset on timeout.
- Back to step 1
- Loss-based
- +1 segment per RTT
- Halves cwnd on loss
- Slow to fill fast, long links
- Loss-based, Linux default
- Growth follows time since last loss
- Cuts cwnd to 70 percent
- Fills queues until they drop
- Model-based
- Measures bandwidth and minimum RTT
- Paces packets at the estimated rate
- Tolerates random loss, smaller queues
- Loss
- Three duplicate ACKs
- SACK holes and RACK timing
- Retransmission timeout
- Delay
- RTT rising above its minimum
- Used by HyStart and BBR
- Explicit marks
- Router sets ECN CE bit
- Receiver echoes with ECE
- Sender replies with CWR
In depth
cwnd, ssthresh and the initial window
The sender tracks two values. cwnd is the current congestion window. ssthresh (slow-start threshold) marks where fast growth stops; it starts very large and is set the first time loss happens.
A new connection starts with an initial window of 10 segments (RFC 6928), about 14 KB with a 1460-byte MSS. That is why web performance guides say the first 14 KB of a page matter: it is all the server can send in the first round trip. In slow start, cwnd grows by one segment for each ACK, which doubles it every RTT. Above ssthresh, in congestion avoidance, it grows by about one segment per RTT.
Linux also falls back to a small window after a connection has been idle (net.ipv4.tcp_slow_start_after_idle = 1 by default). Long-lived connections that send in bursts, such as HTTP/2 or database links, often set this to 0.
- Initial window: 10 segments (about 14 KB)
- Slow start: cwnd doubles per RTT
- Congestion avoidance: about +1 segment per RTT
- ip route change default via GW initcwnd 20 sets it per route
Reacting to loss: fast recovery versus timeout
RFC 5681 describes the classic Reno behaviour. After three duplicate ACKs, the sender knows one packet was lost but later ones are still arriving, so the network is busy but working. It sets ssthresh to half the data in flight (at least 2 segments), resends the missing segment, and continues in congestion avoidance from about that halved value. This is fast recovery.
A retransmission timeout is much worse news: nothing is getting through. The sender sets ssthresh to half, drops cwnd to 1 segment, and starts slow start again. One timeout can cost many round trips of speed.
This pattern, adding a little per RTT and halving on loss, is called AIMD (additive increase, multiplicative decrease). It draws a sawtooth line over time and lets competing flows settle on a fair share. Linux smooths the cut with proportional rate reduction (PRR, RFC 6937).
- 1Slow start
10, 20, 40, 80 over four RTTs
- 23 duplicate ACKs at 80
ssthresh = 40, cwnd = 40
- 3Congestion avoidance
41, 42, 43 ... one per RTT
- 4Timeout at 60
ssthresh = 30, cwnd = 1
- 5Slow start again
1, 2, 4, 8, 16, 30, then +1 per RTT
CUBIC: the Linux default
Reno's growth of one segment per RTT is far too slow for fast, long links. After a loss on a 10 Gbit/s path with 100 ms RTT, it would need well over an hour to grow back. CUBIC (RFC 9438) fixes this.
After a loss, CUBIC cuts cwnd to 70 percent instead of 50 percent. It then grows along a cubic curve based on the time since the last loss, not on the number of ACKs. The curve rises quickly at first, flattens out near the window where the last loss happened (W_max), and then speeds up again to probe for more bandwidth. Because growth depends on time, flows with short and long RTTs share a link more fairly than with Reno. Linux CUBIC also uses HyStart, which leaves slow start early when RTT starts rising, to avoid a large burst of loss.
CUBIC is still loss-based: it keeps filling router queues until packets drop.
BBR: model the path instead of waiting for loss
BBR (Bottleneck Bandwidth and Round-trip propagation time) was published by Google in 2016 and added to Linux 4.9. It keeps two estimates: the highest delivery rate recently seen (the bottleneck bandwidth) and the lowest RTT recently seen (the delay with empty queues). It aims to keep about one bandwidth-delay product in flight and paces packets out at the estimated bandwidth, rather than sending in bursts.
It regularly probes for more bandwidth, and about every 10 seconds it briefly drains the queue to re-measure the minimum RTT. Because random loss does not directly cut its rate, BBR keeps high throughput on lossy links and usually builds smaller queues. The first version could take more than its fair share from CUBIC flows and cause many retransmissions in shallow buffers; later versions (BBRv2 and BBRv3) react to loss and ECN marks to fix this.
Only the sender's algorithm matters: for a download, that is the server.
- Enable: net.ipv4.tcp_congestion_control = bbr
- Pair with net.core.default_qdisc = fq for pacing
- Check: ss -ti shows bbr and pacing_rate
Bandwidth-delay product, ECN and tuning
The bandwidth-delay product (BDP) is how much data must be in flight to keep a link full: bandwidth times RTT. A 1 Gbit/s path with 80 ms RTT needs 10 MB in flight. If cwnd, the receive window or the socket buffers (the third value of net.ipv4.tcp_rmem and tcp_wmem) are smaller than that, one connection cannot fill the link no matter how fast it is.
Loss is a crude signal. With ECN (Explicit Congestion Notification), a router whose queue is growing marks packets instead of dropping them; the receiver echoes the mark with the ECE flag and the sender answers with CWR after slowing down. Linux sets net.ipv4.tcp_ecn = 2 by default: it accepts ECN when the other side asks for it but does not request it itself.
A related problem is bufferbloat: very large queues in home routers make loss-based algorithms fill them, and latency jumps by hundreds of milliseconds under load.
Learn it in 4 short steps
About 40m each. Track them with a timer in your plan.
- 1Explain the congestion window~40m
- 2Trace slow start and congestion avoidance~40m
- 3Explain reaction to packet loss~40m
- 4Compare Reno, CUBIC and BBR~40m
Key points
- Bytes in flight are limited by the smaller of cwnd and the receive window.
- Additive increase, multiplicative decrease keeps flows fair.
- CUBIC is the default on Linux; BBR models bandwidth and RTT instead of reacting to loss.
- Throughput is roughly window size divided by round-trip time.
Key terms
Tap a card to flip it. 0/4 known
Examples
sysctl net.ipv4.tcp_congestion_control # usually cubic
sysctl net.ipv4.tcp_available_congestion_control
ss -ti dst example.com # per-connection cwnd, rttWhy one download crawls across the ocean
A server in Europe sends backups to a site with a 150 ms RTT over a 100 Mbit/s link, but gets only about 10 Mbit/s. Step 1: compute the BDP: 100 Mbit/s x 0.15 s = 15 Mbit, about 1.9 MB that must be in flight. Step 2: check the live connection with ss -ti: a cwnd of about 85 segments x 1448 bytes is only 123 KB. Step 3: work out why. With 0.01 percent loss, a Reno-style flow on a 150 ms path averages roughly 9.5 Mbit/s (the Mathis formula: MSS / RTT x 1.22 / square root of the loss rate). Step 4: test a different algorithm with iperf3, which can pick one per test with -C.
# BDP = 100 Mbit/s x 0.150 s = 15 Mbit = about 1.9 MB in flight
ss -ti dst 198.51.100.20 | grep -oE 'cwnd:[0-9]+|rtt:[0-9.]+|delivery_rate [^ ]+'
sudo iperf3 -c 198.51.100.20 -t 20 -C cubic
sudo iperf3 -c 198.51.100.20 -t 20 -C bbrSwitching a server to BBR and checking it
Step 1: make sure the tcp_bbr module is available. Step 2: write a sysctl file that sets fq as the default queueing discipline (for pacing) and bbr as the algorithm, then load it. Step 3: only new connections use the new algorithm, so open a fresh one and check that ss -ti prints bbr. Step 4: measure before and after with your real traffic; BBR helps most on long or lossy paths and may change little on a clean LAN.
sudo modprobe tcp_bbr
sysctl net.ipv4.tcp_available_congestion_control
printf 'net.core.default_qdisc = fq\nnet.ipv4.tcp_congestion_control = bbr\n' | sudo tee /etc/sysctl.d/90-bbr.conf
sudo sysctl --system
ss -ti state established | grep -c bbrQuick reference
- Bytes in flight are limited by the smaller of cwnd and the receive window
- Initial window is 10 segments (RFC 6928), about 14 KB with a 1460-byte MSS
- Slow start doubles cwnd each RTT; congestion avoidance adds about 1 segment per RTT
- Reno halves cwnd on loss, CUBIC cuts it to 70 percent, a timeout drops it to 1 segment
- BDP = bandwidth x RTT: 1 Gbit/s at 80 ms needs 10 MB in flight
- sysctl net.ipv4.tcp_congestion_control shows the default algorithm (usually cubic)
- Enable BBR: net.core.default_qdisc = fq and net.ipv4.tcp_congestion_control = bbr
- ss -ti shows the algorithm, cwnd, ssthresh, rtt, pacing_rate and delivery_rate
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Find which congestion control algorithm your machine uses, which ones are available, and the cwnd of one live connection.
- Exercise 2medium
Watch slow start happen: add 50 ms of delay on loopback, start a download from a local server and print the server's cwnd several times during the first second.
- Exercise 3hard
Compare CUBIC and BBR on loopback with 50 ms RTT and 1 percent loss using iperf3, and explain the difference.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is BBR always better than CUBIC?
- No. BBR usually wins on long or lossy paths, but on clean, short links the difference is small, and older BBR versions can be unfair to CUBIC flows sharing a bottleneck. Measure with your own traffic before switching.
- Does UDP have congestion control?
- Not by itself. Applications on UDP must add it; QUIC, for example, runs its own congestion control, typically CUBIC or BBR, in user space.
- What is bufferbloat?
- It is the large delay caused by oversized queues in routers and modems. Loss-based algorithms fill these queues before any packet drops, so latency jumps under load; smart queue management (such as fq_codel or CAKE) and BBR reduce it.
- Why do people say the first 14 KB of a web page matter?
- A new TCP connection may send only about 10 segments, roughly 14 KB, before waiting for the first ACKs. Content in that first window reaches the browser one round trip earlier.