TCP vs UDP explained: the difference between the two transport protocols, and when to use each
TCP and UDP are the two main ways programs send data over the internet. TCP opens a connection with a three-way handshake, numbers every byte, resends whatever gets lost and hands the data over in order, so you get everything or an error. UDP skips all of that: it sends independent datagrams with an 8-byte header and no promise that they arrive, arrive once or arrive in order. TCP suits downloads, email and most web traffic; UDP suits video calls, games and DNS lookups, where late data is worse than missing data. HTTP/3 runs on QUIC, which builds its own reliability on top of UDP.
Video · TCP vs UDP: which one should your app use? Under a minute · 0:57
TCP vs UDP in one paragraph
Prefer to watch? The one-minute Short shows the core idea with diagrams; this guide goes further.
Every time two programs talk over the internet, something has to carry their data from one port on one machine to a port on another. That job belongs to the transport layer, and it has two classic protocols. TCP (Transmission Control Protocol) is the careful one: it makes sure everything arrives, complete and in order. UDP (User Datagram Protocol) is the quick one: it sends and moves on.
Neither is better. They make different promises, and the right choice depends on what hurts your app more: data that is late, or data that is missing. If you want to see where the transport layer sits among IP, DNS and HTTP, start with how the internet works.
Throughout this guide we will use one picture. TCP is like mailing a book page by page, with every page numbered, and the reader texting back which pages arrived, so missing ones get mailed again. UDP is like live radio: the presenter keeps talking, and if you miss a word, it is gone.
What TCP is and how it works
The current TCP standard is RFC 9293, and it sums up the service in one line: TCP provides a reliable, in-order, byte-stream service to applications. Each of those words is a promise, and each promise has a mechanism behind it.
The three-way handshake
Before any data moves, the two sides agree to talk. The client sends a SYN (synchronize) segment. The server answers with a segment that carries both SYN and ACK (acknowledge). The client replies with an ACK. RFC 9293 calls this the three-way handshake. It costs one round trip before the first byte of real data can flow.
The handshake is also where each side picks its starting sequence number, which is what makes the next part possible.
Sequence numbers, acknowledgments and resends
TCP gives every byte it sends a sequence number. The receiver sends back acknowledgments that say, in effect, "I have everything up to here." If an acknowledgment does not come back in time, the sender assumes the data was lost and retransmits it. The timeout is not fixed; TCP measures the round trip time and adjusts it as the connection runs.
Because every byte is numbered, the receiver can also put segments back in order when the network delivers them shuffled, and drop duplicates. Your program only ever sees a clean, ordered stream.
Flow control and congestion control
Every TCP segment carries a window: how much more data the receiver is willing to accept right now. That is flow control, and it stops a fast sender from drowning a slow receiver.
Congestion control protects the network itself. RFC 9293 makes it a requirement and points to RFC 5681 for the algorithms: start slowly, speed up while things go well, and back off when packets are lost. That is why a download speeds up over its first seconds.
A stream, not messages
One detail surprises many developers. TCP delivers a stream of bytes, not messages. If you write 100 bytes and then 50 bytes, the other side may read 150 at once, or 30 and then 120. RFC 9293 says plainly that TCP guarantees no link between how data was written and how it is read. Protocols on top of TCP, like HTTP, add their own framing to know where a message ends.
What UDP is and how it works
UDP is defined in RFC 768, a document of about three pages from 1980. It describes a way to send messages "with a minimum of protocol mechanism" and states that "delivery and duplicate protection are not guaranteed."
A UDP datagram carries an 8-byte header with exactly four fields:
| Field | Size | What it does |
|---|---|---|
| Source port | 2 bytes | which program sent it, so a reply can find its way back |
| Destination port | 2 bytes | which program should receive it |
| Length | 2 bytes | the size of the header plus the data |
| Checksum | 2 bytes | lets the receiver detect corrupted data |
That is all. No handshake, no sequence numbers, no acknowledgments, no resends, no window. Each datagram travels on its own. One send is one datagram, so unlike TCP, UDP keeps message boundaries: the receiver gets the whole datagram or nothing.
MDN's summary is a good one: UDP is used when transmission speed and efficiency matter more than reliability, and time-sensitive applications often prefer dropping packets to waiting for delayed ones.
The difference between TCP and UDP, side by side
| TCP | UDP | |
|---|---|---|
| Connection | set up first with a three-way handshake | none, just send |
| Delivery | guaranteed, lost data is resent | not guaranteed |
| Order | always in order | may arrive in any order |
| Duplicates | removed | possible |
| Unit of data | a byte stream | separate datagrams |
| Header size | 20 bytes without options, up to 60 | 8 bytes |
| Flow and congestion control | built in | none, up to the application |
| Latency | higher, waits for handshakes and resends | lower, never waits |
| Typical uses | web (HTTP/1.1, HTTP/2), email, SSH, file transfer | DNS lookups, video calls, games, QUIC |
Why "reliable" is not always better
If TCP guarantees everything, why would anyone give that up? Because the guarantee has a cost, and that cost is waiting.
Picture a video call. Packet 41 is lost. TCP will not hand packet 42 to the app until 41 has been resent and arrived. That stall is called head-of-line blocking. By the time the missing audio arrives, the conversation has moved on. It would have been better to skip it and play the next 20 milliseconds of sound.
That is the real dividing line. Use TCP when every byte matters (a file, a web page, a payment). Use UDP when fresh data beats complete data (a voice, a position in a game, a live sensor reading), or when the exchange is so small that a connection is not worth setting up.
Who uses TCP and who uses UDP
DNS is the classic UDP user (how DNS fits into the bigger picture). A lookup is one small question and one small answer, so a connection would double the time. RFC 1035 calls UDP the recommended method for standard queries. Large answers are marked as truncated so the client can retry over TCP, and zone transfers between servers always use TCP.
Video calls and voice usually send their media over UDP, because a late packet is a useless packet. Many fast online games do the same for player positions, since the next update replaces the last one anyway. The same apps still use reliable channels for things like chat text or a purchase.
The web, email, SSH and file downloads run over TCP, because a web page or a file with a missing chunk is broken. So does the long-lived connection behind a WebSocket, which starts as an HTTP request over TCP.
HTTP/3 and QUIC: reliability on top of UDP
Here is the twist. The newest version of HTTP does not use TCP at all.
HTTP/2 lets a browser send many requests over one TCP connection. But RFC 9114 points out the catch: TCP cannot see those separate requests, so a single lost or reordered packet stalls all of them. HTTP/3 fixes that by moving to QUIC, defined in RFC 9000.
QUIC packets are carried in UDP datagrams, which RFC 9000 says makes it easier to deploy on existing systems and networks. On top of UDP, QUIC rebuilds what it needs: reliable, ordered streams (ordered within each stream, independent of each other), congestion control, and a handshake that includes TLS encryption from the start. A lost packet now only delays the one stream it belonged to.
So the honest answer to "TCP or UDP?" in 2026 is sometimes "UDP, plus your own reliability exactly where you need it."
How to choose for your own app
- Need every byte, in order, and do not want to think about it? Use TCP, usually through HTTP. This covers most APIs and web apps.
- Real-time data where a late update is worthless? Use UDP, and decide in the app how to handle loss.
- Tiny request and reply, like a lookup? UDP saves a round trip. Add a timeout and a retry.
- Want UDP's speed with reliability per stream? Use a QUIC library or HTTP/3 instead of inventing your own protocol.
Whatever you pick, test it the way it will be used. A protocol that feels fine on office Wi-Fi can behave very differently on a phone with 2% packet loss, which is exactly what load and performance testing is for.
Recap
- TCP: a handshake, then a reliable, ordered byte stream. Lost data is resent, the sender slows down when the network is busy.
- UDP: independent datagrams with an 8-byte header. No handshake, no resends, no order, and no waiting.
- Choose by asking what hurts more: late data or missing data.
- DNS, calls and games lean on UDP; web, email and files lean on TCP; HTTP/3 rebuilds reliability on UDP through QUIC.
More guides on networking and backend engineering are in the article library.
Sources: RFC 9293, Transmission Control Protocol · RFC 768, User Datagram Protocol · RFC 5681, TCP Congestion Control · RFC 1035, Domain Names · RFC 9000, QUIC · RFC 9114, HTTP/3 · MDN, UDP
FAQ
What is the main difference between TCP and UDP?
TCP is connection oriented and reliable: it sets up a connection first, then guarantees that every byte arrives, in order, by numbering the data and resending what is lost. UDP is connectionless: it sends each datagram on its own, with no handshake, no resends and no ordering, which makes it lighter and lower latency but leaves reliability to the application.
Is UDP faster than TCP?
UDP starts sending at once and never waits for a lost packet to be resent, so it has lower latency, especially on lossy networks. It is not magically faster on a clean network, and an application that needs every byte would have to rebuild reliability itself. Faster here means less waiting, not more bandwidth.
Why does DNS use UDP?
A typical DNS lookup is one small question and one small answer. Over UDP that is a single round trip with no connection to set up, which RFC 1035 names as the recommended method for standard queries. If an answer is too large, it is marked as truncated and the client can ask again over TCP, which zone transfers always use.
Does HTTP use TCP or UDP?
HTTP/1.1 and HTTP/2 run over TCP. HTTP/3 runs over QUIC, a transport protocol that is carried in UDP datagrams and adds its own reliable, ordered streams, congestion control and built-in TLS encryption on top.
Should I use TCP or UDP for a game?
For fast real-time state such as player positions, UDP is the usual choice, because an old position that arrives late is useless and the next update replaces it anyway. For things that must never be lost, such as chat messages, purchases or the final score, use TCP or a reliable channel built on top of UDP.
Read next
- How Does the Internet Work? Every Networking Concept Explained
- What Is a WebSocket? WebSocket vs SSE vs Polling vs HTTP
- Types of Software Testing: Unit, Integration, E2E and More
- Authentication vs Authorization: Sessions, JWT, OAuth, SSO
- Big O Notation Explained Simply, With Everyday Examples
- Software Engineering Unpacked: home
- The CCAR-F video playlist on YouTube