Skip to main content

Side by side

TCPvsUDP

What is the difference between TCP and UDP?

Updated 2 min read7 differences

In short

TCP opens a connection and guarantees complete, in-order delivery, while UDP sends independent packets with no guarantee, trading reliability for lower latency.

TCP

Transmission Control Protocol

TCP is a core internet protocol that delivers data between two programs reliably and in order, by opening a connection and resending anything that gets lost.

Read the page on TCP

UDP

User Datagram Protocol

UDP is a lightweight internet protocol that sends small, independent messages called datagrams without a connection, favoring speed over guaranteed delivery.

Read the page on UDP

TCP and UDP compared

AspectTCPUDP
ConnectionConnection-oriented; starts with a three-way handshakeConnectionless; sends data right away
ReliabilityGuaranteed delivery with acknowledgments and resendsNo delivery guarantee; lost packets stay lost
OrderingData arrives in the order it was sentDatagrams can arrive out of order
Data unitA continuous stream of bytesIndependent messages called datagrams
Flow and congestion controlBuilt inNone; the application must handle it
Header size20 to 60 bytes8 bytes
Typical usesWeb pages over HTTP/1.1 and HTTP/2, email, file transfer, SSHDNS, video calls, online games, live streaming, QUIC and HTTP/3

The difference, explained

TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are the two main transport protocols on the internet, and both run on top of IP. TCP sets up a connection with a handshake and delivers a reliable, ordered stream of bytes. UDP simply sends self-contained messages called datagrams, with no connection and no promise that they arrive.

The difference exists because applications need different things. TCP numbers every byte, waits for acknowledgments, resends lost data and slows down when the network is congested, which is ideal for web pages, files and email. That care adds delay, so real-time traffic like voice calls, video and games often prefers UDP, where a late packet is useless anyway and it is better to skip it.

Many systems use both. DNS lookups usually use UDP but fall back to TCP for large responses, and HTTP/3 runs on QUIC, a protocol built on UDP that adds its own reliability, encryption and congestion control while avoiding some of TCP's delays. In other words, UDP is often a foundation that applications build their own rules on.

A common misconception is that UDP is always faster or that TCP is slow. UDP has less overhead and no handshake, but on a healthy network TCP is very fast; the real trade-off is whether you need every byte delivered in order or would rather keep going when packets are lost.

Which one should you use?

Choose TCP when…

  • Every byte must arrive, complete and in order.
  • You are transferring files, web pages, API calls or database traffic.
  • You don't want to build reliability logic yourself.

Choose UDP when…

  • Low latency matters more than perfect delivery, as in voice, video or games.
  • Messages are small and independent, like DNS queries or sensor readings.
  • You want to broadcast or multicast to many receivers.
  • You are building your own reliability layer on top, as QUIC does.

Sending a message with each protocol

TCPpython
import socket

# TCP: connect first, then send over a reliable stream
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", 9000))
sock.sendall(b"hello")  # delivered in order, or an error is raised
reply = sock.recv(1024)
sock.close()
UDPpython
import socket

# UDP: no connection; each sendto() is one datagram
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(1.0)
sock.sendto(b"hello", ("127.0.0.1", 9000))  # may be lost silently
reply, addr = sock.recvfrom(1024)
sock.close()

Readers ask

Is UDP faster than TCP?

UDP has lower overhead and no connection setup, so it usually has lower latency. It gets there by skipping reliability, so it is only faster in a useful way if your application can tolerate lost or reordered packets.

Does HTTP use TCP or UDP?

HTTP/1.1 and HTTP/2 run over TCP. HTTP/3 runs over QUIC, which is built on UDP and adds its own reliability and encryption.

Why do online games use UDP?

Games send constant position updates, and a late update is already out of date. With UDP, a lost packet is simply replaced by the next one instead of stalling everything while TCP resends it.

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings