Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
TCP vs UDP explained: handshakes, reliability, ordering, speed and header size, with real use cases from web browsing to gaming, video calls and QUIC.
TCP and UDP are the two main transport protocols of the internet. Both carry data between programs on different machines, on top of IP. They make opposite trade-offs.
Also Read: Why Your Database Needs Connection Pooling - How To's
Quick answer: TCP (Transmission Control Protocol) sets up a connection first and guarantees that every byte arrives, in order, without duplicates. UDP (User Datagram Protocol) just sends packets with no setup and no guarantees. TCP is reliable but adds delay; UDP is fast but can lose data. Web pages, email and file downloads use TCP. Video calls, online games and DNS lookups often use UDP.
| TCP | UDP | |
|---|---|---|
| Connection | Handshake before any data | None; just send |
| Delivery | Guaranteed; lost packets are resent | Best effort; lost packets stay lost |
| Order | Always in order | Can arrive out of order |
| Data model | A continuous byte stream | Separate messages (datagrams) |
| Flow and congestion control | Built in | None; the app must handle it |
| Header size | 20 to 60 bytes | 8 bytes |
| Broadcast / multicast | No | Yes |
| Typical uses | Web (HTTP/1.1, HTTP/2), email, SSH, file transfer | DNS, voice and video calls, games, streaming telemetry, QUIC |
| Specification | RFC 9293 | RFC 768 |
The classic analogy: TCP is a phone call. You dial, wait for an answer, and if they miss a word they ask you to repeat it. UDP is a stream of postcards. You drop them in the box and hope they all arrive; some may come in the wrong order, and one or two may not come at all.

TCP spends a round trip on the handshake and keeps checking in afterwards. When a packet goes missing, the receiver notices the gap and the sender resends it. UDP skips all of that, so it's faster, but a lost packet is simply gone.
IP, the layer underneath, makes no promises. Packets can be dropped, duplicated, delayed or reordered. TCP builds reliability on top with a handful of mechanisms:
All of this is invisible to the application. A program just writes bytes into a socket and reads bytes out the other end, as if through a perfect pipe.
Because TCP delivers bytes strictly in order, one lost packet holds up everything behind it, even data that has already arrived. For a file download that's fine. For a live video call, waiting for a half-second-old frame is worse than skipping it. This problem is also why HTTP/3 moved off TCP.
UDP's header, defined in RFC 768, is just 8 bytes: source port, destination port, length and checksum. That's it. No connection state, no sequence numbers, no retransmissions.
That simplicity buys three things:
UDP doesn't mean "unreliable apps." It means the application decides what reliability it needs. A game might resend important events ("player died") but never resend old position updates.
The rule of thumb: if late data is still useful, use TCP. If late data is useless, consider UDP.
Also Read: Database Sharding Explained: Scaling Past One Machine
| Use case | Protocol | Why |
|---|---|---|
| Web pages (HTTP/1.1, HTTP/2) | TCP | Every byte of HTML, CSS and JS must arrive intact |
| Web pages (HTTP/3) | UDP, via QUIC | QUIC adds its own reliability without TCP's blocking |
| Email (SMTP, IMAP) | TCP | Messages must arrive complete |
| File transfer, SSH, databases | TCP | Correctness beats speed |
| DNS lookups | UDP (TCP for large answers) | One tiny question, one tiny answer |
| Voice and video calls | UDP | A missing 20 ms of audio is better than a delay |
| Online multiplayer games | UDP | Only the newest position matters |
| Video on demand (YouTube, Netflix) | Usually TCP or QUIC | Buffering hides delay, and the picture must be complete |
| WebSockets | TCP | Built on an HTTP connection |
A few of these deserve a closer look:
QUIC, standardised in RFC 9000, runs on UDP but rebuilds TCP's good parts in user space: reliable delivery, ordering, and congestion control. It adds two things TCP can't:
QUIC runs on UDP partly for practical reasons. Routers and firewalls everywhere already pass UDP, while a brand-new transport protocol would be blocked by old network equipment for decades.
UDP has less overhead: no handshake, no acknowledgements, and a smaller header. So it usually has lower latency, especially at connection start and on lossy networks. For bulk downloads on a good connection, TCP's throughput is comparable.
UDP itself doesn't guarantee delivery, but applications can add exactly the reliability they need on top. QUIC is a fully reliable protocol built on UDP.
For real-time data, TCP's guarantees become a liability. Waiting to resend a lost packet makes a video call stutter, and resending an old game position is pointless when a newer one has already been sent.
Yes. TCP and UDP port numbers are separate spaces. DNS, for example, listens on port 53 for both.
Both are transport layer protocols (layer 4 in the OSI model). They sit above IP, which handles addressing and routing, and below application protocols like HTTP, DNS and SMTP.
HTTP/1.1 and HTTP/2 run TLS over TCP. HTTP/3 runs over QUIC, which uses UDP and has TLS 1.3 built in.
TCP and UDP aren't rivals; they're tools for different jobs. TCP trades time for certainty, which is what you want for web pages, email and files. UDP trades certainty for time, which is what you want when data goes stale in milliseconds. QUIC shows the modern answer: start from UDP's flexibility and add only the reliability you need.