TCP vs. UDP: Reliability Against Speed
Understand what TCP guarantees, what UDP leaves to the application and how to tell which one a given job calls for.
Key takeaways
- TCP provides a connection with ordered, reliable delivery plus flow control and congestion control.
- UDP adds little more than port numbers, a length and a checksum to what IP already does.
- TCP's guarantee of order means one lost segment can delay everything behind it.
- Applications built on UDP must handle loss, ordering and sending rate themselves when those things matter.
TCP delivers a stream of data completely and in order, resending whatever gets lost, at the cost of setup time and occasional waiting. UDP sends individual messages with almost no extra machinery: they may arrive, arrive out of order or disappear, and it's up to the application to care. Choose TCP's behavior when every byte matters, and UDP when late data is worthless or the program wants to manage delivery itself.
"Reliability against speed" is a useful shorthand, but it hides the real question. UDP isn't faster on the wire. It simply doesn't make anything wait.
What the transport layer is for
IP gets packets from one machine to another, but makes no promise that they arrive. A busy router may drop packets, and different packets may take different paths. IP also has no notion of which program on the receiving machine a packet is for.
The transport layer fills that gap. Both TCP and UDP add port numbers, which direct data to the right program, as explained in ports explained. Beyond that, they take opposite approaches. For where this layer sits in the bigger picture, see the TCP/IP and OSI models.
How TCP earns its reliability
TCP, specified today in RFC 9293, treats your data as one continuous stream of bytes. It first sets up a connection with a short exchange called the three-way handshake. Then several mechanisms work together.
- Sequence numbers label the position of the data, so the receiver can reassemble it correctly and discard duplicates.
- Acknowledgments report back what has arrived.
- Retransmission resends data that isn't acknowledged in time, or that later acknowledgments show is missing.
- Flow control lets the receiver advertise how much it can accept, so a fast sender doesn't swamp a slow device.
- Congestion control adjusts the sending rate according to signs of crowding in the network, such as loss or rising delay.
Your program sees none of this. It writes bytes in one end and reads the same bytes, in the same order, from the other, or it receives an error saying the connection failed.
One consequence surprises new programmers: TCP doesn't preserve message boundaries. If you send two chunks, the receiver may read them as one, or as three. The application must mark where each message ends, for example with a length field or a delimiter.
What UDP leaves out
UDP, defined in the very short RFC 768, has a header of just 8 bytes: source port, destination port, length and checksum. TCP's header is at least 20 bytes and often larger because of options.
There's no handshake, no acknowledgment, no retransmission and no rate control. Each send produces one datagram, and if it arrives, it arrives as that whole unit. A damaged datagram is detected by the checksum and discarded without notice.
That sounds careless until you see what it enables. A program can send its first useful data immediately. It can send one packet to many receivers on a local network using broadcast or multicast, which a TCP connection can't do. And it decides for itself what to do about loss.
The cost of waiting in line
TCP's ordering promise has a price. Say segments 1 through 5 are sent and segment 2 is lost. Segments 3, 4 and 5 may arrive quickly, but TCP can't hand them to the application until 2 has been resent and received. This is called head-of-line blocking.
For a file download, it hardly matters: you need the whole file anyway. For a voice call, it matters a lot. A fraction of a second of audio that arrives after its moment has passed is useless, and holding newer audio behind it only adds delay. A calling app would rather skip the gap, perhaps masking it, and carry on.
Data after the gap waits until the missing piece is resent.
How TCP decides how fast to send
Congestion control deserves a closer look, because it explains behavior you can see. A new TCP connection doesn't know how much the path can carry. It starts by sending a small amount, then increases quickly as acknowledgments come back, a phase called slow start. When it detects signs of overload, it backs off and then probes upward more gently.
This has two practical effects. Short transfers, such as most small web files, may finish before the connection ever reaches full speed, so round-trip time matters more to them than bandwidth. And a long download over a lossy link may never use the capacity you pay for, because each loss makes the sender slow down.
Several congestion control algorithms exist, and operating systems choose among them. Some react mainly to lost packets, while others estimate the path's capacity and delay. They all aim to use the link fully without collapsing it for everyone else.
Large queues in routers add a twist. If equipment buffers a great deal of data instead of dropping or marking it early, a big TCP upload can fill the queue and add long delays to every other packet, including your call. This is known as bufferbloat, and routers with smarter queue management reduce it.
Who uses which
| Task | Usual transport | Reason |
|---|---|---|
| Web pages over HTTP/1.1 and HTTP/2 | TCP | Content must be complete |
| HTTP/3 | UDP, via QUIC | QUIC rebuilds reliability its own way |
| TCP | Messages can't have holes | |
| File transfer and SSH | TCP | Every byte counts |
| Ordinary DNS lookups | UDP, with TCP when needed | One small question and answer |
| Voice and video calls | Mostly UDP | Fresh data beats complete data |
| Online games | Often UDP | Old positions are quickly obsolete |
| Time synchronization (NTP) | UDP | Small messages, timing sensitive |
These are tendencies, not laws. Much recorded video streaming runs over TCP or QUIC, because the player buffers several seconds ahead, which gives time to recover lost data. Live conversation has no such cushion.
Building reliability on top of UDP
Many applications want some guarantees without all of TCP's behavior. They build exactly what they need above UDP. A game might resend important events such as "door opened" but never resend a position update. A calling system might add forward error correction, which sends extra data that lets the receiver rebuild some losses without asking.
QUIC is the largest example: it provides reliable, encrypted, multiplexed streams over UDP, so a loss on one stream doesn't stall the others. QUIC explained covers how.
Anyone taking this route also takes on responsibility. A program that blasts UDP without reacting to congestion harms other users of the same links. RFC 8085 gives guidance on using UDP responsibly. If you're writing software and aren't sure you need UDP, TCP or an established protocol built on UDP is usually the safer choice.
Firewalls, NAT and security differences
Network equipment treats the two differently. A TCP connection has visible beginnings and endings, so a firewall or home router can track it. UDP has neither, so devices remember a UDP exchange only for a short idle period. Applications send small keepalive packets to hold the path open.
Some restrictive networks block most UDP traffic. That is why calling apps often include a fallback over TCP, which works but may sound worse under loss.
UDP's lack of a handshake also means a source address is easier to forge. Attackers have abused UDP services that send large replies to small requests, bouncing them at a victim. If you run servers, don't expose UDP services to the internet unless they're needed, keep them updated and apply rate limits or the protections the software offers.
Seeing both on your own computer
You can list what your machine is doing. On Windows:
Get-NetTCPConnection -State Established
Get-NetUDPEndpoint On Linux:
ss -t
ss -uln The TCP list shows remote addresses and a connection state. The UDP list mostly shows local ports waiting for datagrams, because there's no connection to describe.
How to choose
Ask three questions about your data.
- Is a missing piece acceptable? If not, you need reliability from TCP, QUIC or your own code.
- Does data lose value quickly? If so, waiting for retransmission hurts, and UDP-based designs fit.
- Do you want to handle the hard parts? Ordering, retries, pacing and encryption take real effort.
For ordinary users there's nothing to switch: applications already pick. Where the knowledge helps is in router and firewall settings, where you may be asked to allow TCP, UDP or both for a particular port. Follow the application's own documentation instead of opening both out of habit.
Common questions
Is UDP less secure than TCP?
Neither encrypts anything on its own. Security comes from protocols such as TLS over TCP, DTLS or QUIC over UDP. UDP services do need particular care against forged source addresses.
Why does my game need specific UDP ports?
Games often send frequent, time-sensitive updates over UDP. Behind a home router, incoming packets may need a known path, so some games document ports to allow or rely on automatic techniques to find one.
Can the same port number be used by both?
Yes. TCP and UDP keep separate sets of ports, so TCP port 53 and UDP port 53 are distinct, and DNS servers commonly listen on both.