# TCP Congestion Control
## What is TCP Congestion Control
TCP congestion control is a mechanism that prevents TCP senders from overwhelming the network by sending too much data too fast. Unlike flow control, which prevents the sender from overwhelming the receiver, congestion control prevents the sender from overwhelming the network infrastructure. Without congestion control, routers would drop large numbers of packets when the network is congested, causing many retransmissions that would further increase congestion, potentially leading to congestion collapse where throughput approaches zero despite high traffic.
## Congestion Window
In addition to the receive window provided by flow control, TCP maintains a congestion window, called cwnd, that limits how much unacknowledged data the sender can have outstanding. The actual transmission rate is limited by the minimum of the receive window and the congestion window. The congestion window starts small and grows as the sender gains confidence that the network can handle more traffic. It shrinks when congestion is detected.
## Slow Start
When a TCP connection is first established or after a timeout, the congestion window starts at one or a small number of maximum segment sizes. In the slow start phase, the congestion window doubles with each round-trip time as long as acknowledgments arrive without loss. This means the window grows exponentially: 1, 2, 4, 8, 16, and so on. Despite the name, slow start grows quite rapidly. Slow start ends when the congestion window reaches the slow start threshold value or when packet loss occurs.
## Congestion Avoidance
When the congestion window exceeds the slow start threshold, TCP switches to the congestion avoidance phase. In this phase, the congestion window grows by approximately one maximum segment size per round-trip time rather than doubling. This linear growth is more conservative and allows the sender to probe for additional capacity without causing congestion.
## Fast Retransmit and Fast Recovery
When the sender receives three duplicate acknowledgments, all acknowledging the same sequence number, it infers that a segment has been lost. It retransmits the lost segment immediately without waiting for the retransmission timeout. This is called fast retransmit. After fast retransmit, the sender enters fast recovery. In the TCP Reno algorithm, fast recovery reduces the slow start threshold to half the current congestion window and sets the congestion window to the new threshold plus three, then continues in congestion avoidance. The TCP NewReno and SACK algorithms improve on Reno's behavior when multiple segments are lost in a single window.
## Timeout-Based Congestion Response
When the retransmission timer expires, TCP infers severe congestion. It sets the slow start threshold to half the current congestion window, resets the congestion window to one maximum segment size, and restarts the slow start process. This aggressive reduction is because a timeout indicates more severe congestion than three duplicate acknowledgments.Back to Subject