Networking

TCP vs UDP

TCP vs UDP explained simply. Which one guarantees delivery, which one is faster, and when interviewers expect you to pick each.

TCP
Transmission Control Protocol
VS
UDP
User Datagram Protocol
The short answer

TCP sets up a connection and guarantees your data arrives in order, so use it when correctness matters more than speed. UDP fires packets with no handshake and no guarantee, so use it when speed matters more than the odd lost packet.

TCP vs UDP at a glance

TCPUDP
ConnectionConnection oriented, handshake firstConnectionless, sends immediately
Delivery guaranteeGuaranteed, retransmits lost packetsNot guaranteed, packets can be dropped
OrderPackets arrive in orderPackets can arrive out of order
SpeedSlower due to handshake and acknowledgementsFaster, minimal overhead
Header size20 bytes8 bytes
Typical useWeb pages, email, file transferVideo calls, gaming, DNS lookups

When to use each

Choose TCP when

  • You are loading a web page or API response that must be complete and correct.
  • You are transferring a file and cannot afford missing bytes.
  • You are sending a database query where every byte matters.

Choose UDP when

  • You are streaming live video or audio where a dropped frame is fine.
  • You are building a multiplayer game and need the lowest possible latency.
  • You are doing a quick DNS lookup where retrying is cheap and fast.

Why the difference exists

TCP was built for reliability. Before any data moves, the two sides perform a three way handshake, then TCP tracks every packet with sequence numbers and resends anything that goes missing. That reliability costs time. UDP skips all of it. It just sends the packet and hopes it arrives, which makes it much faster but leaves error handling to the application if it needs any.

A simple way to remember it

Think of TCP as a phone call where both sides confirm they can hear each other before talking, and UDP as shouting across a room where you assume the message lands but do not wait for confirmation.

In the interview

A common follow up is why video calls use UDP instead of TCP. The answer is that a slightly glitchy frame now is better than a perfect frame that arrives late, because TCP would pause everything to redeliver a lost packet in order.

Frequently asked questions

Is TCP always slower than UDP?

In raw throughput UDP has less overhead, but modern TCP implementations are fast enough for almost all everyday use. The real difference shows up in latency sensitive applications like gaming or live video.

Can an application use both TCP and UDP?

Yes. Many video call apps use UDP for the audio and video stream but TCP for signalling data like joining a call, since that data must arrive correctly.

Does HTTP use TCP or UDP?

Traditional HTTP and HTTPS run over TCP. HTTP 3 introduces QUIC, which runs over UDP but adds its own reliability layer on top.

Want more interview ready comparisons?

Browse every TCP vs UDP style breakdown, or explore the full question library.

All comparisons Browse questions