Side by side

PropertyTCPUDP
ConnectionConnection-oriented — three-way handshake requiredConnectionless — just send
ReliabilityGuaranteed delivery via acknowledgment and retransmissionNo guarantee — a lost datagram simply vanishes
OrderingGuaranteed in-order delivery to the applicationNo ordering guarantee
Flow controlSliding window (demo below)None
Congestion controlYes — backs off automatically when the network is overloadedNone — the application must self-limit
Header overhead20+ bytes8 bytes
Typical usesWeb (HTTP), email, file transfer, SSHDNS queries, voice/video calls, gaming, live streaming

Flow control: the sliding window

A receiver only has so much buffer space. Its receive window tells the sender exactly how many unacknowledged segments it can have in flight at once. Every time an ACK arrives, the window slides forward by one, making room to send the next segment. Try sliding the window yourself:

5 segments

Congestion control: the TCP sawtooth

Beyond the receiver's window, TCP also tracks its own estimate of how much the network can handle: the congestion window (cwnd). It starts small and grows — fast at first, then cautiously — until a loss tells it to back off. Repeated over time this produces TCP's famous sawtooth shape:

Slow start — cwnd doubles every round trip Congestion avoidance — cwnd grows by 1 per round trip Loss event — ssthresh halves, cwnd drops with it

Hover the chart to read exact values. Why it looks like this: growing exponentially (slow start) would risk overshooting the network's real capacity, so TCP switches to a cautious linear climb (congestion avoidance) once it's in roughly the right range — then treats any loss as a signal it pushed too far, and cuts back hard before climbing again.

When to reach for which

Common gotchas