All articles
165 articles · updated weekly See our Tools
All articles
Comparisons

TCP vs UDP: differences and applications

TCP guarantees delivery and order at the cost of latency; UDP fires and forgets to cut delay. Learn when each fits and why QUIC blends the two.

TCP vs UDP: differences and applications
COVER · Comparisons

You open a ticket because "the video call freezes, but downloads work fine." The network team says everything's up. Both use the same infrastructure, the same IP, the same cable — so why does one suffer and the other doesn't? The answer is almost never in the physical link. It's in the transport layer: TCP and UDP solve the same problem (move bytes from one process to another across the network) with opposite philosophies, and that difference defines what breaks and how it breaks.

This piece explains what each protocol guarantees, what it charges for that guarantee, and how to choose between them without falling for the cliché that "TCP is safe, UDP is fast."

What TCP delivers — and the cost

TCP is connection-oriented. Before any data flows, both sides run the three-way handshake (SYN, SYN-ACK, ACK), which synchronizes sequence numbers and confirms both are ready. From there, TCP promises three things: reliable delivery (every lost segment is detected and resent via retransmission), guaranteed order (bytes reach the application in the same sequence they left), and congestion control (the sender slows down when the network signals saturation, instead of flooding the path).

That bundle of guarantees is why TCP underpins HTTP, email (SMTP/IMAP), and file transfer. When you download an 800 MB installer, you don't tolerate a single byte out of place — and that's exactly what TCP delivers.

The price is latency. The handshake costs at least one round trip before the first useful byte. Worse: guaranteed order creates the head-of-line blocking problem. If segment 5 is lost, segments 6, 7, and 8 may have already arrived, but the application won't get them until 5 is retransmitted and reassembled. For a download that's irrelevant; for live audio, it's the freeze that generates the ticket.

What UDP does NOT deliver — on purpose

UDP is the opposite: connectionless, "fire and forget." No handshake, no sequence numbers, no retransmission, no built-in congestion control. You pack a datagram, send it to an IP and a port, and the protocol promises neither that it arrives, nor that it arrives in order, nor that it arrives exactly once.

That sounds like a defect until you look at the header. The UDP header is 8 bytes (source port, destination port, length, checksum). TCP's is at least 20 and carries all the sequence, ACK, and window state. Less overhead per packet, zero setup round trips, no queue waiting on retransmission. Minimal latency.

The trade-off becomes explicit:

              TCP                         UDP
setup         3-way handshake             none
delivery      guaranteed + retransmit     best effort
order         guaranteed (HOL blocking)   none
header        >= 20 bytes                 8 bytes
control       congestion control          none (left to the app)
best for      files, HTTP, email          DNS, games, voice, live video

UDP shines exactly where a late packet is worse than a lost one. In real-time voice and video, retransmitting an audio frame from 200 ms ago is useless — the conversation has already moved on. Better to drop it and play the next one. Online games would rather lose a position update and get the next one fresh than wait for the old one. Live streaming follows the same logic. Loss exists, but the application decides what to do with it — hide it, interpolate, ignore it — instead of letting transport stall everything.

DNS: the case that uses both

DNS is the textbook example of why UDP makes sense. A name lookup is typically a short question and a short answer: "what's the IP of example.com?" → "203.0.113.10". Opening a TCP handshake for that would be absurd — three ceremony packets to exchange two content packets. That's why DNS was born over UDP on port 53: one question, one answer, minimal latency. If the answer is lost, the resolver simply asks again.

But UDP has a practical datagram size limit (historically 512 bytes, now extended via EDNS0). When the answer doesn't fit — many records, DNSSEC, large zones — the server signals truncation and the client redoes the query over TCP, where fragmentation and reliability are handled. In other words: DNS uses UDP by default and falls back to TCP when size demands it. If you want to see that flow in detail, I wrote a step-by-step on how a DNS query happens.

Both TCP and UDP carry packets between IP addresses, and part of the diagnostic work is knowing where the traffic actually comes from. Inspecting a source IP helps separate "the protocol is wrong" from "the destination is wrong."

QUIC and HTTP/3: the best of both

The classic split isn't the end of the story. QUIC, which underpins HTTP/3, runs over UDP — but reimplements, in user space, the reliability, per-stream ordering, and congestion control that TCP brings in the kernel. The move is clever: by using UDP as a base, QUIC escapes head-of-line blocking between streams (a loss in one stream doesn't stall the others) and the middlebox ossification that makes evolving TCP hard. You get TCP's guarantees without inheriting its structural limits. It's proof that "reliable UDP" isn't a contradiction — it's a choice about where to put the complexity.

How I choose in practice

My rule is blunt: when in doubt, it's TCP. Reliability and order are the behavior most applications assume without noticing, and erring on the safe side costs only latency — something you can measure and usually tolerate. Most of what you build (APIs, uploads, integrations) wants TCP, full stop.

Choose UDP deliberately, not by reflex of "I want speed." The criterion is specific: latency matters more than perfect delivery, and you accept handling loss in the application itself. If you don't have a plan for what to do when a packet vanishes — hide the glitch, request state again, interpolate — then you're not ready for UDP, you're just giving up the guarantees for free. UDP isn't "fast TCP"; it's TCP without a safety net, and the safety net becomes your responsibility.

Frequently asked questions

Is TCP always slower than UDP?

Not in sustained throughput — over stable connections TCP moves a lot of data efficiently. What UDP wins is setup latency and the absence of head-of-line blocking. For a large download TCP is usually equal or better; for a small, time-sensitive packet, UDP arrives first.

Can I get reliability while using UDP?

Yes, but you implement it on top. That's exactly what QUIC does: it uses UDP as raw transport and rebuilds retransmission, ordering, and congestion control in user space. For ordinary projects it rarely pays to rewrite that by hand — use a library or fall back to TCP.

Why do online games use UDP if they can lose packets?

Because in a real-time match a late packet is already stale by the time it arrives. A position from 100 ms ago is useless if the next one is already on the way. The game prefers to drop the old update and use the new one rather than wait for a retransmission that only delays everything.

How do I know which protocol a service uses?

By the port number and the socket type. Conventions help: 80/443 (HTTP) are TCP, 53 (DNS) uses both, 443 also carries HTTP/3 over UDP via QUIC. Tools like netstat, ss, or a packet capturer show explicitly whether the connection is TCP or UDP.

What to take away

TCP and UDP don't compete — they split the work. TCP pays latency to deliver reliability and order, and it's the correct default for nearly everything. UDP gives up those guarantees to cut latency, and it's worth it when a late packet hurts more than a lost one and you have a plan for loss. Decide by what hurts most when something fails: if it's a byte out of place, TCP; if it's delay, UDP. And remember QUIC has already blurred the line — the modern question isn't "TCP or UDP," but "where do I want to pay for reliability?"

RD
Author
Rafael Duarte
Backend developer with a background in fintech and B2B SaaS — worked on teams that scaled APIs from zero to millions of requests. Carries enough production scars to hold strong opinions on tools, patterns and architecture decisions. Not an academic: he read the UUID RFC when he had to choose between v4 and v7 for a write-heavy table.
View profile