Search

TCP vs UDP: Why the Internet Needs Both

TCP vs UDP: Why the Internet Needs Both

The short answer

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.

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.

TCPUDP
ConnectionHandshake before any dataNone; just send
DeliveryGuaranteed; lost packets are resentBest effort; lost packets stay lost
OrderAlways in orderCan arrive out of order
Data modelA continuous byte streamSeparate messages (datagrams)
Flow and congestion controlBuilt inNone; the app must handle it
Header size20 to 60 bytes8 bytes
Broadcast / multicastNoYes
Typical usesWeb (HTTP/1.1, HTTP/2), email, SSH, file transferDNS, voice and video calls, games, streaming telemetry, QUIC
SpecificationRFC 9293RFC 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.

The difference in one picture

Diagram: The same lost packet over TCP and over UDP

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.

How TCP guarantees delivery

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:

  1. Three-way handshake. SYN, SYN-ACK, ACK. Both sides agree on starting sequence numbers before any data flows. Cloudflare's TCP/IP explainer walks through it.
  2. Sequence numbers. Every byte is numbered, so the receiver can reassemble data in the right order and throw away duplicates.
  3. Acknowledgements (ACKs). The receiver reports how much it has received. Anything unacknowledged after a timeout, or flagged as missing by repeated ACKs, is retransmitted.
  4. Checksums. Each segment carries a checksum, so corrupted data is detected and discarded.
  5. Flow control. The receiver advertises how much buffer space it has left, so a fast sender can't overwhelm a slow receiver.
  6. Congestion control. TCP starts slowly and speeds up while things go well, then backs off when packets are lost. This keeps millions of connections from collapsing the network.
  7. Graceful close. FIN and ACK messages make sure both sides have finished before the connection is torn down.

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.

The hidden cost: head-of-line blocking

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.

How UDP stays fast

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:

  • No setup delay. The first packet carries real data.
  • No waiting on the past. Each datagram is handled on its own, so a lost one doesn't stall the rest.
  • Low overhead. A server can handle huge numbers of clients without tracking connections. Cloudflare's UDP explainer notes this is also why UDP is popular for flood attacks.

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.

When to use TCP vs UDP

The rule of thumb: if late data is still useful, use TCP. If late data is useless, consider UDP.

Use caseProtocolWhy
Web pages (HTTP/1.1, HTTP/2)TCPEvery byte of HTML, CSS and JS must arrive intact
Web pages (HTTP/3)UDP, via QUICQUIC adds its own reliability without TCP's blocking
Email (SMTP, IMAP)TCPMessages must arrive complete
File transfer, SSH, databasesTCPCorrectness beats speed
DNS lookupsUDP (TCP for large answers)One tiny question, one tiny answer
Voice and video callsUDPA missing 20 ms of audio is better than a delay
Online multiplayer gamesUDPOnly the newest position matters
Video on demand (YouTube, Netflix)Usually TCP or QUICBuffering hides delay, and the picture must be complete
WebSocketsTCPBuilt on an HTTP connection

A few of these deserve a closer look:

QUIC: the best of both

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:

  • Independent streams. A lost packet only stalls the stream it belongs to, not every stream on the connection.
  • Built-in encryption. Connection setup and the TLS 1.3 handshake happen together, saving a round trip.

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.

Frequently asked questions

Is UDP faster than TCP?

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.

Is UDP unreliable?

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.

Why doesn't everything just use TCP?

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.

Can a port use both TCP and UDP?

Yes. TCP and UDP port numbers are separate spaces. DNS, for example, listens on port 53 for both.

What layer are TCP and UDP?

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.

Does HTTPS use TCP or UDP?

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.

Conclusion

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.

Related articles

Sources and further reading

Usama Muneer

Usama Muneer

Coder, Blogger, Tech Speaker & Web Technologies Enthusiast. Passionate about working on open-source Programming languages & Tools while utilizing my Product Development skills.

Your experience on this site will be improved by allowing cookies Cookie Policy