Course contents

Unit 7: TCP, UDP and PortsLesson 7.1.10 (10 of 23 in this unit)59 of 104 in the Network Fundamentals course

How UDP works

If a voice packet arrives too late to play, should the call wait for it? Let's see what UDP provides and what the application must decide for itself.

Beginner · 6 min read

Covers UDP header, Connectionless and Real-time traffic.

Technical definition

UDP (User Datagram Protocol) is a connectionless transport layer protocol that sends each datagram with a small 8-byte header holding the source and destination ports, a length and a checksum. It sets up no connection and does not acknowledge, reorder or resend data, leaving that to the application if it needs it.

A video call over patchy Wi-Fi

You are on a video call, and a few packets are lost on your Wi-Fi link. The application may conceal a short audio gap, reduce video quality, recover some loss or discard late data. Those are application decisions, not guarantees supplied by UDP. TCP delivers an ordered byte stream, which can delay later bytes behind a missing earlier byte; whether that matters depends on the application and its deadline.

Connectionless, with an 8-byte header

Compare two DNS messages: a query from 192.168.1.20:53000 to 192.168.1.53:53, then a reply with those endpoints reversed. The UDP header supplies ports, a length and a checksum; it has no sequence or acknowledgement fields. If the reply is lost, a DNS client can retry after its own timeout. UDP does not automatically perform that retry.

No UDP handshake does not mean the application has no state or cannot provide reliability. QUIC, used by HTTP/3, runs over UDP and supplies its own connection, recovery and congestion-control mechanisms. Similarly, an operating system can associate a UDP socket with a peer without exchanging a TCP-style handshake.

UDP (User Datagram Protocol) is the simpler of the two main transport protocols. It is connectionless: UDP itself has no connection handshake or closing exchange. Each message, called a datagram, is sent on its own. UDP does not number datagrams, confirm them or resend them. This is called best-effort delivery.

Source port16 bits
Destination port16 bits
Length16 bitsheader + data, in bytes
Checksum16 bits

Read each row from left to right. The ruler gives bit positions 0–31 within that row; field sizes are labelled in bits or bytes.

The whole UDP header: four fields, 8 bytes. The TCP header is at least 20 bytes.
Diagram
Connectionless, with an 8-byte header
Connectionless, with an 8-byte header
FieldJob
Source portThe sending application; replies are sent back to this port
Destination portThe receiving application, for example 53 for DNS
LengthSize of the header plus data, in bytes; at least 8
ChecksumDetects damaged datagrams; optional in IPv4, required in IPv6
Each item on the left, with what it means on the right.

UDP preserves datagram boundaries and supplies endpoint ports, length and checksum information. It does not supply TCP's delivery acknowledgements, ordering, retransmission or windows. Additional recovery and traffic control belong to the application or another protocol layered over UDP.

Diagram
Voice over UDP: lost packets are skipped, not resent
Voice over UDP: lost packets are skipped, not resent
IP phone AIP 10.10.1.21R1R2IP phone BIP 10.20.1.35

Device key: IP phone A, IP phone B (desk phone) · R1, R2 (router)

Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type. Blocked: forwarding prevented by a port or policy. Down: failed link. Read the step for the cause.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • IP phone A: IP 10.10.1.21
  • IP phone B: IP 10.20.1.35
  1. 1. Every 20 ms phone A sends a small UDP datagram containing a slice of sound.
  2. 2. One is lost on the WAN. UDP does not notice that it is missing, and nothing asks for it again.
  3. 3. The next one plays. Phone B hides the 20 ms gap and keeps playing. A late resend would be worse than a tiny gap.

Voice, DNS, DHCP and other UDP users

Diagram
Voice, DNS, DHCP and other UDP users
Voice, DNS, DHCP and other UDP users
ApplicationWhy UDP suits it
Voice and video callsLate data is useless; skipping is better than waiting
Online gamesOnly the newest position matters
DNSOne small question, one small answer; the client simply asks again if it is lost
DHCPThe client has no IP address yet and must send broadcasts
NTP, SNMP, syslogSmall, regular messages; one lost message does little harm
Streaming to many receiversMulticast needs UDP, because TCP cannot hold a handshake with every receiver
Each item on the left, with what it means on the right.

Some applications want reliability but not TCP's exact rules, so they build their own on top of UDP. QUIC, used by HTTP/3 on UDP port 443, is the best-known example: it provides its own encryption, retransmission and ordering.

What UDP gains by doing less

Less work means less delay. There is no handshake, so the first datagram already carries real data. There is no waiting for ACKs, and no stall when one datagram is lost. The small header also saves bandwidth: a voice packet may carry only 20 to 160 bytes of sound, so saving 12 bytes on every packet adds up. The cost is that the application must deal with loss, duplicates and out-of-order data itself.

UDP counters on a Cisco router

show ip traffic includes UDP counters for traffic sent to and from the router itself. The output below is based on Cisco documentation, not captured from a lab device, and shows only the UDP part.

Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show ip traffic | section UDP
UDP statistics:
  Rcvd: 4093 total, 0 checksum errors, 312 no port, 0 finput
  Sent: 2240 total, 0 forwarded broadcasts
What to look for: checksum errors counts damaged datagrams, which are discarded. no port counts datagrams sent to a UDP port where nothing was listening. UDP has no RST, so the router normally replies to these with an ICMP “port unreachable” message instead.

Because there is no handshake, a blocked UDP service is harder to diagnose than a blocked TCP one. A firewall that drops the traffic and a server that simply does not answer look the same from the client: silence. A packet capture on each side is often the quickest way to tell them apart.

Test yourself on UDP

Predict · scenario 1

You compare a DNS query in a packet capture with a TCP segment. How big is the UDP header in the DNS query?

Predict · scenario 2

A UDP datagram carrying part of a voice call is lost on a WAN link. What does UDP do?

Predict · scenario 3

You are writing a firewall rule that allows only UDP traffic to a web server. Which of these services runs over UDP?

Technical references

RFC 768: UDP fields; RFC 8085: application responsibilities over UDP; RFC 9000: QUIC over UDP.