The opening part of NetFun III showed that a conversation on the internet is named by five numbers: a protocol, two addresses and two ports. For one of the two great transports, that name and a length are almost the whole protocol. The User Datagram Protocol (UDP) adds to the Internet Protocol (IP) exactly what is needed to reach a program and to notice damage, and nothing else: no connection, no order, no retransmission, no flow or congestion control. This part reads its specification field by field, decodes a datagram from its bytes, computes its checksum by hand, and then walks through everything UDP leaves to the application and to the network, from message size to middlebox timers to the attacks that exploit a protocol with no handshake. After it you can decode a UDP header by eye, verify a checksum on paper, and list what any protocol built on UDP, from the Domain Name System (DNS) to QUIC, has to do for itself.

Three pages from 1980

UDP's specification is 768, written by of the University of Southern California's Information Sciences Institute and dated 28 August 1980. It runs to three pages, and its introduction states the design in two sentences: "This protocol provides a procedure for application programs to send messages to other programs with a minimum of protocol mechanism. The protocol is transaction oriented, and delivery and duplicate protection are not guaranteed." The third sentence sends everyone else elsewhere: "Applications requiring ordered reliable delivery of streams of data should use the Transmission Control Protocol (TCP)" (RFC 768).

The note names its first users, "the Internet Name Server, and the Trivial File Transfer", and gives its number: "This is protocol 17 (21 octal) when used in the Internet Protocol" (RFC 768). Forty-six years later the Internet Assigned Numbers Authority () still lists protocol 17 as UDP with "RFC 768; Jon Postel" as its reference (IANA, Assigned Internet Protocol Numbers). The specification has not been replaced, because there has been almost nothing to change.

The header, field by field

RFC 768 draws the whole header in four lines of eight bytes:

BytesFieldSizeWhat RFC 768 says
0 to 1Source Port16 bits"an optional field"; when meaningful, the port of the sending process, which "may be assumed to be the port to which a reply should be addressed"; "If not used, a value of zero is inserted"
2 to 3Destination Port16 bits"has a meaning within the context of a particular internet destination address"
4 to 5Length16 bits"the length in octets of this user datagram including this header and the data", so "the minimum value of the length is eight"
6 to 7Checksum16 bits"the 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data", padded with a zero octet to an even length
8 onwardsdatavariablethe application's message

That is the protocol. There is no sequence number, because nothing is ordered; no acknowledgement, because nothing is confirmed; no window, because the receiver is never asked how much it can take. Each send becomes one IP datagram, and the receiver gets the whole message or nothing. The Linux manual describes the result plainly: "a connectionless, unreliable datagram packet service. Packets may be reordered or duplicated before they arrive. UDP generates and checks checksums to catch transmission errors" (Linux man-pages, udp(7)).

The length field sets a ceiling: 16 bits allow 65,535 octets including the 8-octet header. The IPv4 header's own Total Length field allows a datagram "to be up to 65,535 octets", internet header included, and that header is at least 5 words of 32 bits, 20 octets (RFC 791, section 3.1); so the largest UDP payload over IPv4 is 65,535 − 20 − 8 = 65,507 octets, the figure RFC 8085 gives along with 65,527 for IPv6 (RFC 8085, section 1). Nobody should send that much in one datagram, for reasons the section on size gives.

Worked example: a DNS query, decoded from its bytes

Here is a complete UDP datagram, 37 bytes in hexadecimal, as a capture would show it. A host at 192.0.2.10 sends it to a resolver at 198.51.100.53 (both from the blocks RFC 5737 reserves for documentation):

c3 50 00 35 00 25 66 12 1a 2b 01 00 00 01 00 00
00 00 00 00 07 65 78 61 6d 70 6c 65 03 63 6f 6d
00 00 01 00 01

The first eight bytes are the UDP header:

BytesHexFieldDecimalReading
0 to 1c3 50Source Port12 × 4096 + 3 × 256 + 5 × 16 + 0 = 50,000an ephemeral port in the dynamic range
2 to 300 35Destination Port3 × 16 + 5 = 53"domain" in IANA's registry: DNS
4 to 500 25Length2 × 16 + 5 = 378 bytes of header plus 29 of data, matching the 37 bytes captured
6 to 766 12Checksum0x6612verified in the next section

The 29 bytes after the header are the DNS message. Read with RFC 1035's layout, they are a 12-byte header (identifier 0x1a2b; flags 0x0100, the recursion-desired bit; one question, no answers) followed by one question: the name written as labels, 07 then "example", 03 then "com", 00 to end it, then type 00 01 (an A record, an IPv4 address) and class 00 01 (Internet) (RFC 1035, sections 4.1.1 and 4.1.2). The name is one RFC 2606 reserves for examples (RFC 2606, section 3). The DNS message header and flags reads those 12 bytes bit by bit; what matters here is that UDP neither knows nor cares. It delivered 29 bytes to port 53, and its whole contribution is the 8 bytes in front.

Notice what the length field implies about message boundaries. The resolver's receive call returns this one datagram, all 29 bytes of it, and no more. The Linux manual says so: "All receive operations return only one packet. When the packet is smaller than the passed buffer, only that much data is returned; when it is bigger, the packet is truncated and the MSG_TRUNC flag is set" (udp(7)). A TCP receiver, by contrast, gets a byte stream with no edges, which is why Python sockets for network engineers needs a whole section on framing for TCP and none for UDP.

Worked example: the checksum by hand

The rules

The Internet checksum is defined once and reused by UDP, TCP and others. RFC 1071 (September 1988), by Robert Braden, David Borman and Craig Partridge, gives it in outline: "Adjacent octets to be checksummed are paired to form 16-bit integers, and the 1's complement sum of these 16-bit integers is formed"; to generate it, "the checksum field itself is cleared, the 16-bit 1's complement sum is computed over the octets concerned, and the 1's complement of this sum is placed in the checksum field"; to check it, the sum is computed over the same octets including the checksum field, and "If the result is all 1 bits (-0 in 1's complement arithmetic), the check succeeds" (RFC 1071, section 1). On ordinary two's complement hardware, the one's complement sum is computed "by means of an "end around carry", i.e., any overflows from the most significant bits are added into the least significant bits" (same section).

The standard's own example first

RFC 1071 works one sum in section 3, over the eight bytes 00 01 f2 03 f4 f5 f6 f7. Done by hand as 16-bit words:

WordHex
10001
2f203
3f4f5
4f6f7
Sum2ddf0
Fold the carry: ddf0 + 2ddf2

The RFC's table reaches the same ddf2 by every route it tries, byte by byte, word by word in either byte order, and 32 bits at a time (RFC 1071, section 3). The checksum that would go in a header is the one's complement of that sum: ffff − ddf2 = 220d. Keep these two numbers, ddf2 and 220d: they are the test any checksum calculator, or any hand calculation, must pass first.

The pseudo-header

UDP's checksum covers more than UDP. RFC 768 adds a "conceptually prefixed to the UDP header" with "the source address, the destination address, the protocol, and the UDP length", and gives the reason: "This information gives protection against misrouted datagrams" (RFC 768). The pseudo-header is never sent; both ends build it from the IP header and include it in the sum. For our datagram over IPv4 it is 12 bytes:

BytesFieldValueWords
4source address192.0.2.10 = c0 00 02 0ac000, 020a
4destination address198.51.100.53 = c6 33 64 35c633, 6435
1 + 1zero, then protocol 1700 110011
2UDP length37 = 00 250025

The sum, step by step

Add the pseudo-header, the UDP header with its checksum field set to zero, and the data padded with one zero byte to an even length (29 bytes of data become 15 words, the last one 01 00).

PartWordsRaw sumAfter folding the carry
Pseudo-headerc000 + 020a + c633 + 6435 + 0011 + 00251eca8eca8 + 1 = eca9
UDP header, checksum 0c350 + 0035 + 0025 + 0000c3aac3aa
Data1a2b + 0100 + 0001 + 0000 + 0000 + 0000 + 0765 + 7861 + 6d70 + 6c65 + 0363 + 6f6d + 0000 + 0100 + 01001e997e997 + 1 = e998

Because one's complement addition is associative (RFC 1071, section 2), the three partial sums can be added in any order:

  1. eca9 + c3aa = 1b053; fold: b053 + 1 = b054.
  2. b054 + e998 = 199ec; fold: 99ec + 1 = 99ed.
  3. The checksum is the complement: ffff − 99ed = 6612.

That is the 66 12 in bytes 6 and 7 of the capture. RFC 768 adds one special case: "If the computed checksum is zero, it is transmitted as all ones", because an all-zero field means something else.

The check on arrival

The receiver repeats the sum with the checksum field left in: 99ed (the sum of everything else) + 6612 = ffff, all ones, so "the check succeeds". Change a single bit anywhere in the 37 bytes, or deliver the datagram to the wrong address, and the sum stops being ffff. The Python playground is enough to rerun every line of this table.

What the checksum protects, and the rules around it

The checksum catches accidental damage and misdelivery; it is not a signature, and anyone who changes a datagram on purpose can recompute it. Within those limits the rules are strict.

  • IPv4: optional, on by default, and drop if wrong. RFC 768 allows a sender to skip it: "An all zero transmitted checksum value means that the transmitter generated no checksum". The host requirements of October 1989 narrowed that freedom: "A host MUST implement the facility to generate and validate UDP checksums. An application MAY optionally be able to control whether a UDP checksum will be generated, but it MUST default to checksumming on", and "If a UDP datagram is received with a checksum that is non-zero and invalid, UDP MUST silently discard the datagram" (RFC 1122, section 4.1.3.4). The same section records why: applications that turned checksums off for local networks met "numerous cases of undetected errors", and "The advisability of ever turning off UDP checksumming is very controversial".
  • IPv6: mandatory. RFC 8200 makes UDP's checksum compulsory: "Unlike IPv4, the default behavior when UDP packets are originated by an IPv6 node is that the UDP checksum is not optional", a computed zero becomes ffff, and "IPv6 receivers must discard UDP packets containing a zero checksum and should log the error" (RFC 8200, section 8.1). The IPv6 pseudo-header carries the 128-bit addresses, the upper-layer length and the next header value instead of IPv4's fields (same section).
  • The tunnel exception. RFC 8200 lets "protocols that use UDP as a tunnel encapsulation" enable a zero-checksum mode on specific ports, under the conditions of RFC 6936 (April 2013), so that tunnel endpoints are spared a sum over every encapsulated packet (RFC 8200, section 8.1; RFC 6936).

What UDP leaves to the application

Everything TCP does, the application on UDP either does itself or does without. Going through the list is the fastest way to understand both UDP and why TCP is as large as it is.

ConcernWhat UDP doesWho handles itWhere the rule is
Reaching the programdestination portUDPRFC 768
Detecting damagechecksumUDPRFC 768, RFC 1122
Lossnothingthe application: timers and retries, or toleranceRetries, timeouts and idempotency
Order and duplicatesnothing: "may be reordered or duplicated"the application, if it caresudp(7)
Message boundariespreserved: one send, one datagram, one receiveUDPudp(7)
Sizeup to 65,507 bytes over IPv4 on paper; fragmentation beyond the path's maximum transmission unit ()the application should stay under the path MTURFC 8085
Congestionnothingthe application SHOULD control its rateRFC 8085
Telling the sender nobody listensnothing in UDP; the host may send an Internet Control Message Protocol () messageICMPRFC 792, RFC 1122

Three rows deserve the numbers.

Size. The UDP usage guidelines, RFC 8085 (March 2017, Best Current Practice 145), notes in its introduction that "Fragmentation decreases communication reliability and efficiency and should be avoided" (section 1), says applications "SHOULD avoid IP fragmentation", and tells them to discover the path's Maximum Transmission Unit (MTU) or else fall back to messages "shorter than the default effective MTU for sending": "For IPv4, EMTU_S is the smaller of 576 bytes and the first-hop MTU", and "For IPv6, EMTU_S is 1280 bytes" (RFC 8085, section 3.2). Linux does for UDP by default, keeps track of the MTU to each destination and returns the error EMSGSIZE "when a UDP packet write exceeds it" (udp(7)). DNS wrote its own limit into its specification in 1987: "UDP messages 512 octets or less" (RFC 1035, section 2.3.4). QUIC chose a floor rather than a ceiling: "QUIC MUST NOT be used if the network path cannot support a maximum datagram size of at least 1200 bytes", and "UDP datagrams MUST NOT be fragmented at the IP layer" (RFC 9000, section 14). The tunnel overhead part shows how fast a path's MTU shrinks once headers are stacked.

Congestion. UDP will send as fast as the application writes. RFC 8085 asks applications to take the responsibility TCP takes for them: an application "SHOULD perform congestion control over all UDP traffic it sends", and one that exchanges little data and cannot keep a round-trip estimate "SHOULD NOT send more than one UDP datagram every 3 seconds" (RFC 8085, sections 3.1 and 3.1.3). The part on TCP flow and congestion control shows what that responsibility involves.

Nobody listening. When a datagram reaches a port with no socket, UDP itself says nothing; the host's Internet Control Message Protocol (ICMP) may. RFC 792 (September 1981) lists the destination unreachable codes, among them "3 = port unreachable", and RFC 1122 says that when a datagram arrives for a port with no pending listener, "UDP SHOULD send an ICMP Port Unreachable message" (RFC 792; RFC 1122, section 4.1.3.1). On Linux the application learns of it as ECONNREFUSED, "No receiver was associated with the destination address", and the manual warns that the error "might be caused by a previous packet sent over the socket" (udp(7)). If the ICMP message is filtered on the way back, the sender hears silence, which is indistinguishable from a datagram lost on the way out or an answer lost on the way back.

UDP and the middleboxes: state without a protocol

A stateful firewall or a translator follows a TCP connection by its handshake and its close. UDP has neither, so a box in the middle can only open state when a datagram passes and close it after a period of silence. The firewall part shows the entry such a box creates; the timers are set by two documents.

  • For network address translators (), RFC 4787 requires that "A NAT UDP mapping timer MUST NOT expire in less than two minutes" and recommends "A default value of five minutes or more" (RFC 4787, section 4.3).
  • For applications, RFC 8085 records the gap between rule and practice: "NATs require a state timeout of 2 minutes or longer", but "empirical evidence suggests that a significant fraction of currently deployed middleboxes unfortunately use shorter timeouts". An application that must keep state alive "SHOULD NOT transmit them more frequently than once every 15 seconds and SHOULD use longer intervals when possible", the 15 seconds coming from the Interactive Connectivity Establishment (ICE) protocol (RFC 8085, section 3.5).

Worked example: the cost of keeping a mapping alive

A softphone behind a home translator must be reachable for incoming calls, so its mapping must not expire.

  1. At RFC 8085's floor of one keep-alive every 15 seconds, one device sends 86,400 ÷ 15 = 5,760 keep-alives a day. At 28 bytes each before any payload (8 of UDP and the 20 of a minimal IPv4 header), that is 161,280 bytes a day of headers alone, per device.
  2. If the translator honours RFC 4787's recommended five minutes, one keep-alive every 4 minutes would do, with a minute to spare: 360 a day, sixteen times fewer.
  3. If a translator in the path uses a 30-second timer, which RFC 8085 says happens, the 4-minute schedule loses the mapping after 30 seconds of silence, and the next call from outside finds no entry and is dropped.

The application cannot see which translators sit in its path, which is why RFC 8085 recommends the shorter interval when the environment is unknown and asks deployers to measure when it is not.

Why new protocols are built on UDP

UDP's emptiness is also its appeal. A new transport sent as its own IP protocol number would have to pass every firewall and translator on the internet, most of which recognize only TCP and UDP. Built inside UDP, it passes wherever UDP passes. QUIC says this in its overview: "QUIC packets are carried in UDP datagrams to better facilitate deployment in existing systems and networks" (RFC 9000, section 1). Everything UDP omits, QUIC supplies itself: connection identifiers, encryption, streams, acknowledgements, loss recovery and congestion control, as QUIC streams, loss and migration explains. The same reasoning explains many older protocols on UDP whose exchanges fit in one datagram, from DNS to the Network Time Protocol () and the Simple Network Management Protocol (): a query and an answer that each fit in a datagram would pay a round trip for a TCP handshake before asking anything.

The missing handshake: reflection and amplification

TCP's handshake proves, before any data flows, that the client can receive packets at the address it claims. UDP has no such step, so a server answers whatever source address a datagram carries. QUIC's specification describes the consequence that this opens: "a packet is sent to a server with spoofed source address information that identifies a victim. If a server generates more or larger packets in response to that packet, the attacker can use the server to send more data toward the victim than it would be able to send on its own" (RFC 9000, section 8).

The Cybersecurity and Infrastructure Security Agency (CISA) measures the effect with a bandwidth amplification factor (BAF), "the number of UDP payload bytes that an amplifier sends to answer a request, compared to the number of UDP payload bytes of the request". Its alert TA14-017A, last revised on 18 December 2019, lists, among others (CISA, UDP-Based Amplification Attacks):

ProtocolBandwidth amplification factor in TA14-017ACommand
DNS28 to 54(an earlier alert, TA13-088A)
NTP556.9(an earlier alert, TA14-013A)
SNMPv26.3GetBulk request
SSDP (Simple Service Discovery Protocol)30.8SEARCH request
CharGEN358.8character generation request
Memcached10,000 to 51,000

Worked example: what the factor means

An attacker with a 10 Mbit/s uplink sends spoofed NTP requests carrying the victim's address. With CISA's factor of 556.9, the amplifiers send the victim about 10 × 556.9 = 5,569 Mbit/s of UDP payload, more than 5.5 Gbit/s from a 10 Mbit/s connection, and the victim sees the traffic coming from the amplifiers, not from the attacker. With DNS at its upper factor of 54, the same uplink yields 540 Mbit/s. The factors count payload bytes only; headers change the totals a little and the conclusion not at all.

QUIC shows the defence built into a protocol: until an address is validated, an endpoint "MUST limit the amount of data it sends to the unvalidated address to three times the amount of data received from that address", the anti-amplification limit (RFC 9000, section 8). Three, against 556.9. The other defence sits with the networks the spoofed packets come from: ingress filtering, Best Current Practice 38, written in May 2000 "to prohibit DoS attacks which use forged IP addresses to be propagated from 'behind' an Internet Service Provider's () aggregation point", DoS being denial of service (RFC 2827). How networks absorb a distributed denial-of-service () flood is in DDoS: what actually absorbs an attack, which follows the attack to the defender's side.

The Brazilian angle: a national notification programme

Every reflection attack needs amplifiers, and amplifiers are ordinary devices answering on UDP to anyone: home routers that act as open DNS resolvers, switches with SNMP open to the internet, servers with old NTP configurations. In Brazil the Center for Studies, Response and Treatment of Security Incidents (), part of (Núcleo de Informação e Coordenação do Ponto BR), receives reports from partners about addresses in Brazilian networks that offer these services, and notifies the contacts registered for each autonomous system in Registro.br's (the domain and address registration lookup); the Programa por uma Internet mais Segura (Programme for a Safer Internet) then works with the networks that have the most amplifiers (NIC.br, Programme for a Safer Internet, Against amplification attacks (in Portuguese)).

The programme's page lists the services it acts on with their ports, all UDP: open recursive DNS servers (53), SNMP (161), misconfigured NTP servers (123), SSDP (1900), Portmap (111), NetBIOS (137) and the Ubiquiti Networks device discovery service (10001). Its definitions are exact. A recursive DNS server is open "when it accepts recursive queries indiscriminately, from any network on the Internet, on port 53, using the UDP protocol" (our translation here and below); an NTP server is open to amplification when it accepts commands "such as monlist or readvar" that produce answers much larger than the question; for SNMP the advice is to disable the service if unused, restrict it to the local network otherwise, and avoid the "public" community (same page).

The figures, from a NIC.br presentation of 22 August 2025 (NIC.br, Programme for a Safer Internet (in Portuguese), Juazeiro do Norte, 22 August 2025):

At the start, February 2018August 2025
Services notified519
Addresses with misconfigured services746,508150,935
Of which NTP52,329
Of which SNMP47,686
Of which DNS32,387
Autonomous systems9,009 in Brazil, 5,316 notified

The presentation gives the reduction as 79%; by hand, 1 − 150,935 ÷ 746,508 = 1 − 0.2022 = 0.798, so the stated figure is the rounded-down 79.8%, achieved while the list of services monitored grew from 5 to 19. The same presentation pairs the notifications with source address validation, through unicast reverse path forwarding (uRPF), ingress access lists and Source Address Validation Improvement (SAVI), under the routing-security actions of MANRS (Mutually Agreed Norms for Routing Security). The two halves are the two defences of the previous section: fewer amplifiers to answer, and fewer networks that let spoofed requests out.

What defenders can do

  • Do not offer UDP services to the internet that the internet does not need: recursion, SNMP, NTP control queries and discovery protocols belong on the local network, as NIC.br's notifications ask.
  • Filter spoofed sources where your network meets its customers (BCP 38); a network that lets forged addresses out is the attacker's launch pad.
  • When designing a protocol on UDP, validate the client's address before sending large answers, as QUIC's three-times limit does, and keep answers to unauthenticated requests small.
  • Watch for UDP in both directions on the ports in CISA's table; a burst of large answers from your network to one destination is an amplifier being used.

What to remember

  • UDP is an 8-byte header: source port (optional, zero if unused), destination port, length (at least 8, header included) and checksum. Protocol 17 since RFC 768 of 28 August 1980.
  • The checksum is the one's complement of the one's complement sum over a pseudo-header (addresses, protocol, length), the header and the padded data; RFC 1071's example sums to ddf2, checksum 220d. Optional but on by default in IPv4, mandatory in IPv6 except in RFC 6936 tunnels.
  • One send is one datagram and one receive: boundaries survive, order, delivery and rate are the application's problem. Stay under the path MTU: 576 bytes for IPv4 and 1,280 for IPv6 when it is unknown (RFC 8085).
  • Middleboxes keep UDP state on timers: at least two minutes for NAT mappings by rule, often less in practice; keep-alives no more often than every 15 seconds.
  • No handshake means no proof of the source address: reflection and amplification follow, with factors from 6.3 for SNMPv2 to 556.9 for NTP in CISA's table; QUIC limits itself to three.

Sources