TCP Algorithms

In this post, I want to document the fundamental algorithms built into TCP. Keep in mind that these have changed over time in an attempt to make TCP more effective with faster and larger capacity connections of todays Internet. See our post on TCP “versions” here.

TCP uses several key algorithms to manage connection setup/teardown, flow control, congestion control, and retransmission and Selective Acknowledgement.

Here’s a breakdown of the main categories and their associated algorithms:

1. Connection Management Algorithms

Used during setup and teardown of TCP sessions.

  • Three-Way Handshake: SYN, SYN-ACK, ACK to establish a connection – otherwise called the three way handshake.
  • Four-Way Termination: FIN, ACK, FIN, ACK sequence to tear down a connection – a four way exchange.

2. Flow Control Algorithm

The TCP flow control algorithm is the Sliding Window Protocol, designed to ensure the sender does not overwhelm the receiver by sending more data than it can handle. This is accomplished using what is called a Sliding Window Protocol: the Receiver first advertises a window size (rwnd) that the sender must respect.

Receiver Window (rwnd):

  • Set by the receiver. We see in the diagram that the receiver has set a 3 segment rwnd.
  • Advertised in all TCP headers.
  • Represents how much buffer space the receiver has left.
  • Controls how much more data the sender can transmit.

Sender Behavior:

  • Maintains a send window, which slides forward as ACKs are received.
  • Can only send data within the limits of the rwnd (receiver window) and cwnd (congestion window, from congestion control).
  • If rwnd = 0, the sender stops sending and probes periodically with zero window probes.

Acknowledgments:

  • The receiver acknowledges received segments and advertises an updated rwnd.
  • As ACKs arrive, the sender’s window advances (“slides”), allowing more data to be sent.

We further see in my diagram that the receiver updates the rwnd to four segments in the first ACK. This then allows the sender to send 2 packets to fill the window. After this, assuming the rwnd stays the same only one packet will be sent after each ACK.

The TCP Sliding Window Protocol dynamically adjusts how much data can be in transit between sender and receiver based on the receiver’s ability to process and buffer that data.

3. Congestion Control Algorithms

Illustration of Congestion Control with Slow Start, the Slow Start Threshold (SSTHRESH) and Congestion Avoidance.

These help prevent congestion collapse and manage traffic efficiently. As seen below and also discussed here, this is where TCP has changed over time.

  • Slow Start: Increases congestion window (cwnd) exponentially at the start of a connection.
  • Congestion Avoidance (Additive Increase/Multiplicative Decrease – AIMD): Increases cwnd linearly, halves it on loss.
  • Fast Retransmit: Detects packet loss via triple duplicate ACKs and retransmits without waiting for a timeout.
  • Fast Recovery: Temporarily inflates cwnd during recovery to keep packets flowing after Fast Retransmit.
  • TCP Tahoe: Implements Slow Start, AIMD, and Fast Retransmit; resets cwnd to 1 on loss.
  • TCP Reno: Adds Fast Recovery to Tahoe.
  • TCP NewReno: Improves Fast Recovery by handling multiple lost segments per window.
  • TCP Vegas: Uses RTT estimates to detect congestion before packet loss.
  • TCP BIC/CUBIC: Used in Linux; optimized for high-speed, long-distance networks.
  • BBR (Bottleneck Bandwidth and RTT): Google’s model-based algorithm measuring actual bandwidth and RTT, not loss.

4. Retransmission Algorithms

Manage how lost packets are retransmitted.

Original TCP Retransmission on left. SACK Retransmission on the right.
  • RTO (Retransmission Timeout): Sets a timer; if ACK not received, packet is retransmitted.
  • Karn’s Algorithm: Avoids ambiguous RTT measurements for retransmitted segments.
  • Exponential Backoff: Increases RTO exponentially after consecutive timeouts.

5. Selective Acknowledgment (SACK) and Recovery

  • SACK: Allows the receiver to inform the sender exactly which segments were received.
  • DSACK (Duplicate SACK): Indicates duplicate segments received, helping tune retransmission behavior.

I hope that helps those who are new to TCP to understand the TCP algorithms that try to guarantee delivery of data to a Receiver. I will cover details of these in later posts. Just click on the TCP tag below to quickly find all posts regarding TCP.

Comments are welcomed below from registered users.  You can also leave comments at our Discord server

If you would like to see more content and articles like this, please support us by clicking the patron link where you will receive free bonus access to courses and more, or simply buying us a cup of coffee!

Scroll to Top