esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

UDP: Fast Packets With No Delivery Promise, and When That Is the Right Trade

UDP sends packets with no setup, no resending, and no order. That makes it fast and light, which suits live calls and games, and it is why newer protocols like QUIC rebuild some safety on top of it.

In short

UDP sends packets with no setup, no resending and no order, which makes it fast and light for live calls and games.

12 min readFree

What you will learn

When one computer sends data to another over a network, the data is cut into small pieces called packets. Each packet is a block of data with a label that says where it should go, and each one can take its own path. A transport protocol is a set of rules that decides how those packets are sent and what the sender can count on. UDP, short for User Datagram Protocol, is one of the two main transport protocols. The other is TCP.

In this lesson you will learn how UDP works, what it gives up compared with TCP, and when system designers choose it. You will also see how a live video call uses it, and how newer protocols such as QUIC add reliability back on top of it.

Key words

Packet
A small block of data sent across a network, with addressing labels on it.
Datagram
The name UDP uses for one independent message. A UDP datagram is sent alone and does not depend on the ones before or after it.
Transport protocol
A set of rules that moves data between two programs on different machines and sets the rules for reliability and speed.
TCP
Transmission Control Protocol. It sets up a connection first and tries to deliver every byte, in order.
Handshake
A short set of messages two machines exchange to agree they will talk before they send real data.
Retransmission
Sending a packet again because the first copy was lost or not confirmed.
Ordering
Making sure data arrives in the same order it was sent.
Latency
The delay between sending something and the other side getting it.
Header
The small block of labels added in front of the data inside a packet.

How does UDP work?

UDP is defined in RFC 768, a document first published in 1980 and written by J. Postel. The protocol is part of the internet protocol suite, and it is described as a light way for programs to send messages with very little extra machinery. It runs on top of IP, the Internet Protocol, which handles getting packets to the right machine.

The main idea is that UDP is connectionless. A sender does not open a session with the receiver first. It just writes a datagram, gives it an address, and sends it. Every datagram stands alone.

Because the protocol is so small, it has very few rules. It does not check whether a message arrived. It does not ask for it again. It does not put messages back in order. These gaps are the source of both its speed and its risk.

Each UDP datagram carries a header followed by the data the program wants to send. The header has four fields, and each field is two bytes long, so the whole header is eight bytes. The fields are a source port, a destination port, a length, and a checksum. A port is a number that tells the receiving machine which program should get the data. The checksum is a check value that helps spot damaged data. For IPv4, the checksum is optional.

What is the eight-byte header?

The sample below builds a header with a source port of 5000, a destination port of 53, a length of 20, and a checksum of 0. It packs the four two-byte fields in a fixed layout and prints the size and the bytes in hex, which is a way of writing bytes as pairs of digits.

Python
import struct

header = struct.pack('!HHHH', 5000, 53, 20, 0)
print(len(header))
print(header.hex())

Output

8
1388003500140000

The output is 8 for the size, because the header is eight bytes long. The hex text shows each field in turn: 1388 is 5000, 0035 is 53, 0014 is 20, and 0000 is the checksum with no value set.

What does UDP leave out?

Compared with TCP, UDP leaves out several jobs. Each missing job is a choice the protocol makes on purpose, to keep the work per packet small.

  • No handshake

    The sender can start sending at once. It does not wait for the receiver to agree to a session first.

  • No resending

    If a packet is lost, UDP does not send it again. UDP has no built-in retransmission, so any recovery has to come from the app.

  • No ordering

    Datagrams can arrive in a different order from the one they were sent in. They can also arrive twice, or not at all.

  • No congestion control

    UDP does not slow down when a network gets crowded. The app has to avoid flooding the network on its own.

What is the trade-off between UDP and TCP?

TCP is built for cases where every byte matters. It sends data in a connection, checks what arrived, and resends what did not, so the receiver gets a complete and ordered stream. Those guarantees cost time and work. The full details of how TCP does this belong to a separate lesson, so here we only compare the gains and costs of choosing UDP instead.

What do you gain with UDP?

Choosing UDP gives four main benefits. Each one follows from the fact that UDP does less work.

  • Low latency

    Without a handshake and without waiting for resends, data can move right away. This keeps the delay short, which matters for live use.

  • Low overhead

    The header is only eight bytes, and the protocol keeps little state. TCP's header is larger, and it must track more work for each connection.

  • No head-of-line blocking

    Head-of-line blocking means one stuck item holds up everything queued behind it. Under TCP, a lost packet can make newer data wait while the old packet is resent. UDP does not make newer data wait for an old one.

  • Broadcast and multicast

    Multicast means sending one datagram to a group of receivers, and broadcast means sending it to every machine on a local network. TCP is built for one link between two endpoints, but UDP's connectionless design allows these one-to-many uses.

What you give up

The price of those gains is reliability. A UDP packet can be lost, duplicated, or arrive out of order, and UDP will not tell the sender. Error handling is light, so an app that needs complete and ordered data must build that itself. That is why UDP is sometimes called the Unreliable Datagram Protocol. The name is a fair warning, not a mistake. The app owns the risk.

Tip

Think of UDP as a fast delivery service that never checks for signatures. The package may arrive early, late, twice, or not at all. If your app cannot live with that, either add checks in the app or choose TCP.

When the app must handle loss

Because UDP gives no ordering, an app that cares about order has to add its own labels. A common method is a sequence number, which is a counter the sender writes into each message. The receiver can then see which message is newest and ignore older ones that arrive late. The sample below sends three updates where the second one arrives last.

Python
arrivals = [(1, 'x=10'), (3, 'x=30'), (2, 'x=20')]
latest = None
for seq, value in arrivals:
    if latest is None or seq > latest[0]:
        latest = (seq, value)
    print(seq, value)
print('use', latest[1])

Output

1 x=10
3 x=30
2 x=20
use x=30

The receiver prints all three messages in the order they came in. The third printed line shows message 2 arriving after message 3. Because the receiver compares sequence numbers, it keeps x=30 as the value to use. The app did the ordering work that UDP skipped.

When to choose UDP

UDP is a good fit when a late packet is worth less than a fresh one, or when the app can work around a missing piece. Ask two simple questions. Is this data still useful if it arrives late? Can the app live with a small gap? If both answers are yes, UDP is worth a look.

  • Live voice and video

    A short glitch is usually better than a long pause. Real-time media puts low latency ahead of perfect delivery. A resent packet of sound often arrives after it can still be played.

  • Online games

    Players send their positions many times each second. A newer position makes an older one useless, so the game can skip the old one and use the next update.

  • DNS lookups

    The Domain Name System turns names into addresses. A lookup is a short question and a short answer. Sources list DNS queries among the common uses of UDP.

  • Streaming telemetry

    Telemetry means readings sent from sensors or servers to a monitor, often many times a second. Losing one reading usually matters less than keeping the stream current.

How QUIC and HTTP/3 add reliability back

Some newer protocols use UDP as a base and rebuild the features UDP lacks. QUIC is the best-known example. One source describes QUIC as a layer that adds reliability on top of UDP, which is not reliable by itself.

QUIC also uses separate streams. A stream is one ordered sequence of data inside the connection. Because the streams are separate, a lost packet that affects one stream does not have to stop the others. This removes much of the head-of-line blocking that TCP can cause. HTTP/3 does not use UDP instead of reliability. It uses UDP as the base and rebuilds reliability above it.

Worked example: a live video call

Take a live video call, such as one in Zoom or Google Meet. We did not check how either app is built inside, so read this as a general walk-through of the pattern. Digital Samba says WebRTC builds reliability on UDP.

  1. 1

    Capture small pieces

    The microphone and camera produce a steady flow of small pieces of sound and picture. The sender places each piece in its own UDP datagram.

  2. 2

    Send without asking first

    The sender does not do a handshake before each piece. It sends each datagram straight away, so the delay from speaker to listener stays low.

  3. 3

    One piece is lost

    Suppose a datagram carrying a short slice of sound is lost on the way. UDP does not notice and does not resend it.

  4. 4

    The receiver plays on

    The receiver plays the pieces that did arrive. The listener may hear a brief click, and the picture may freeze for a moment, but the call keeps going.

  5. 5

    Why a resend would not help

    A resent copy would reach the receiver after the moment had already passed. Under TCP, newer pieces could wait behind the old one. The whole stream would stall, which is worse than a short glitch.

Tip

Real-time apps often hide small losses with buffering, which means holding a little media before playing it, and error concealment, which means filling a gap with a smooth guess from nearby data. Both help UDP feel steady to the user.

Check your understanding

Try these short scenarios. Each one needs the ideas from this lesson to answer.

Quick check

You are building a live multiplayer game that sends each player's position 30 times per second. One packet carrying a position is lost. Which protocol fits best, and why is resending the lost packet unhelpful?

Quick check

An app downloads a software installer. Every byte must match exactly, and the download can take a little longer if it has to wait for a resend. Which choice should the designer make?

Quick check

A team wants fast web delivery and wants one lost packet to stall only the part of the page it belongs to. They are considering a protocol built on UDP. Which statement is correct?

Key takeaways

UDP sends independent datagrams with no handshake, no resending, and no ordering. Its eight-byte header keeps the work small, which gives low latency and low overhead, and it allows multicast and broadcast. The cost is that packets may be lost, duplicated, or arrive out of order, so the app must handle any loss it cannot accept.

Choose UDP when fresh data matters more than complete data, as in live calls, games, and DNS lookups. Choose TCP when every byte must arrive in order. When you need both speed and reliability, consider a protocol like QUIC, which builds reliability on top of UDP.

Sources

How is this lesson?

Last updated on 17 November 2026

Learn with me

Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.