TCP vs UDP: Connection Setup, Reliability, Ordering, Congestion Control, Header Size, Latency and Uses
TCP and UDP are both transport-layer protocols that run on top of IP and use port numbers to identify applications. Before sending data, TCP establishes a connection with a three-way handshake; it confirms delivery with acknowledgments (ACKs), retransmits lost data and hands data to the receiving application in the order it was sent. It also adjusts how much it sends to the receiver's free buffer space (flow control) and to network congestion (congestion control). UDP does none of this: it simply sends data as datagrams, so its header is small and there is no wait before sending. Use TCP when reliable delivery matters, and UDP when low delay matters and the application handles whatever else it needs.
| Aspect | TCP | UDP |
|---|---|---|
| Connection setup | Connection-oriented: data follows a three-way handshake (SYN → SYN+ACK → ACK), so there is an initial wait of one round trip (RTT) | Connectionless: data can be sent immediately, with no setup |
| Acknowledgment and retransmission | Delivery is confirmed with ACKs; loss is detected by a retransmission timeout or duplicate ACKs, and the lost data is resent | No acknowledgment or retransmission; lost data stays lost |
| Ordering | Sequence numbers are used to reorder data and deliver it in the order it was sent; duplicates are removed | Data is delivered in arrival order; reordering and duplication can occur |
| Data boundaries | A byte stream with no boundaries; the application decides where messages begin and end | Each send becomes one datagram, so message boundaries are preserved |
| Flow and congestion control | Yes: the receive window keeps the receiver's buffer from overflowing, and the congestion window adapts the amount sent to congestion | None; if needed, the application adjusts its own sending rate |
| Header size | 20 bytes without options (up to 60 bytes with options) | 8 bytes (source and destination ports, length, checksum) |
| Latency | Connection setup costs one round trip; after a loss, later data also waits until the retransmission arrives | No setup and no waiting for retransmissions, so delay is low, but some data may be missing |
| Destination types | One-to-one (unicast) only | Unicast, and also broadcast and multicast |
| Typical uses | The web over HTTP/1.1 and HTTP/2, video delivery over HTTP, email (SMTP), SSH, file transfer | DNS queries, DHCP, real-time traffic such as voice calls and live video, online games, and QUIC used by HTTP/3 |
Figures are typical orders of magnitude and vary by process generation and product.