TCP vs UDP
Reliable and ordered, or fast and best-effort — the transport trade-off.
TCP is connection-oriented: a 3-way handshake sets up a reliable, ordered, error-checked stream with flow and congestion control — great for web, email and file transfer, but with overhead. UDP is connectionless and best-effort: no handshake, no ordering guarantee, minimal overhead and low latency — ideal for video, voice, gaming and DNS.
Two philosophies
TCP is connection-oriented and guarantees a reliable, ordered byte stream; UDP is connectionless and fires off best-effort datagrams with no promises. Every difference below flows from that single design choice about who is responsible for reliability — the transport, or the application. TCP takes on that burden for you; UDP hands it back so you can decide.
Reliability
TCP numbers every byte, waits for acknowledgements, and retransmits anything that isn't confirmed, so data always arrives complete and intact. UDP does none of this — a dropped datagram is simply gone, and the sender never even knows. If reliability matters over UDP, the application itself must detect and recover from loss.
Speed
UDP skips the three-way handshake and all per-packet bookkeeping, so a datagram can leave immediately with minimal latency. TCP must first spend a full round trip on SYN / SYN-ACK / ACK before any data flows, and its acknowledgement and retransmission machinery can stall a stream while it waits for a lost packet. UDP trades those guarantees away for raw immediacy.
Ordering
TCP reassembles bytes in the exact order they were sent, buffering later data until earlier gaps are filled — which is also the source of its head-of-line blocking. UDP makes no ordering promise at all: datagrams can arrive out of order, duplicated, or not at all, and the receiver takes them as they come. Applications that need order over UDP add their own sequence numbers.
Overhead
A TCP header is 20+ bytes and each connection carries per-socket state for sequence numbers, windows, and congestion control. UDP's header is just 8 bytes with essentially no state, which is why latency-sensitive and high-fan-out applications — DNS, video, gaming — prefer it. Less machinery means less delay and less memory per connection.
One layer, two answers
TCP and UDP sit at the same place in the stack — the transport layer, riding directly on top of IP. IP by itself only knows how to shove a packet toward an address; it makes no promise that the packet arrives, arrives once, or arrives in order. TCP and UDP are the two standard answers to the question "given that unreliable delivery, what should the transport hand to the application?"
TCP answers: a reliable, ordered, error-checked stream of bytes, as if the two endpoints had a clean private wire between them. UDP answers: nothing extra — here are your datagrams, delivered if the network manages it, in whatever order they show up. Neither is "better." They are two points on a deliberate trade-off between guarantees and speed, and almost every property that distinguishes them descends from that one decision about how much work the transport does on your behalf.
How TCP builds reliability
A TCP connection begins with the three-way handshake: the client sends a SYN, the server replies SYN-ACK, the client answers ACK. After those three messages both sides have agreed on starting sequence numbers and the connection is open. That setup costs a full round trip before any real data moves, which is the price of a stateful, reliable channel.
Reliability itself comes from sequence numbers and acknowledgements. TCP numbers every byte it sends; the receiver acknowledges what it has received, and any data not acknowledged within a timeout is retransmitted. The receiver reorders segments that arrive out of sequence and discards duplicates, so the application always reads a clean, in-order stream. A checksum on every segment catches corruption. The connection is finally torn down gracefully with FIN packets. All of this state — sequence numbers, timers, buffers — is what makes TCP reliable and what makes it heavier than UDP.
Flow control and congestion control
TCP does more than deliver bytes; it protects both the receiver and the network. Flow control stops a fast sender from overwhelming a slow receiver: the receiver advertises a *window* saying how much buffer space it currently has, and the sender never has more unacknowledged data in flight than that window allows.
Congestion control protects the shared network from overload. TCP starts cautiously (slow start), ramps its sending rate up until it detects loss — which it treats as a signal of congestion — then backs off and probes again, using algorithms like CUBIC or BBR. This is why TCP throughput ramps rather than jumping to full speed, and why many simultaneous TCP flows fairly share a link instead of collapsing it. UDP has none of this by default, which is both its advantage (no self-imposed slowdown) and its danger: a misbehaving UDP application can flood a network with no built-in restraint, so real-world UDP protocols usually add their own congestion control.
UDP: minimal by design
UDP is almost the absence of a transport protocol, and that is the point. Its header is a mere 8 bytes — source and destination ports, length, and a checksum — versus TCP's 20-plus bytes and per-connection state. There is no handshake, no acknowledgements, no ordering, no flow or congestion control. You hand UDP a datagram and it hands it to IP; whether it arrives is the network's business.
That minimalism buys two things. Latency: data leaves on the first packet with no setup round trip and no waiting on retransmissions. Simplicity and scale: a server can field datagrams from huge numbers of clients without holding open connection state for each. The cost is that any guarantee you need — reliability, ordering, deduplication, pacing — you must build yourself in the application. UDP is best understood not as "unreliable TCP" but as a blank canvas: it gives you IP's raw datagrams plus ports, and gets out of your way.
Choosing, and where the line is blurring
The rule of thumb: choose TCP when correctness is non-negotiable and a small delay is acceptable, and choose UDP when timeliness beats completeness. TCP underpins the web (HTTP/1 and HTTP/2), email, SSH, and file transfer — anywhere a missing or reordered byte would corrupt the result. UDP underpins live video and voice, online gaming, and DNS, where a slightly dropped frame or a quick retry beats a stalled stream waiting on retransmission.
That said, the boundary is not as fixed as it looks. Real-time media over UDP still layers its own sequencing and loss concealment on top. And the most important modern example, QUIC (the transport under HTTP/3), is built *on UDP* precisely so it can implement TCP-style reliability, ordering, and congestion control in user space — while avoiding TCP's per-stream head-of-line blocking. In other words, engineers reached for UDP not because they wanted unreliability, but because they wanted to build a *better* reliable protocol than TCP without being stuck inside the operating system kernel. The takeaway: pick the transport whose defaults match your needs, and remember you can always build guarantees up from UDP, but you can't easily shed TCP's.
TCP is connection-oriented: a 3-way handshake precedes data, guaranteeing reliable, ordered, error-checked delivery.
TCP adds flow and congestion control, which cost round-trips and overhead but protect the network and receiver.
UDP is connectionless: no handshake, no delivery or ordering guarantees — packets are fire-and-forget.
UDP's tiny overhead means low latency, which suits real-time media, gaming, DNS and streaming.
Choose TCP when correctness matters (web, email, file transfer); choose UDP when timeliness beats completeness.
Quick quiz
Why is UDP preferred for live video and gaming?
What does TCP's 3-way handshake set up?
HTTP/1 → HTTP/2 → HTTP/3
Three generations of the web's request protocol, each killing the last one's bottleneck.
How HTTPS works
The TLS handshake that turns a plain TCP connection into a private, verified channel.
How DNS works
Turning a human name into a machine address by walking a global hierarchy.
What happens when you type google.com
The single most-asked interview question, animated end to end.