UDP: The Header, the Checksum and the Pseudo-Header
What UDP gives an application on top of IP, the 8-byte header field by field, how the checksum and pseudo-header are computed (worked from a real packet), zero checksums in IPv4 and IPv6, checksum offload in captures, and what happens at a closed port.
kvi5hnuCode Sprout team member17 min readOn this page
The User Datagram Protocol (UDP) is the thinnest transport protocol in the TCP/IP suite. It adds exactly two things to IP: port numbers, so a datagram reaches the right program, and a checksum, so damaged datagrams can be detected. Everything else that TCP does is missing on purpose:
- No connection setup. The first datagram can carry data immediately.
- No reliability. A lost datagram stays lost unless the application sends it again.
- No ordering or duplicate removal. Datagrams can arrive in any order, and occasionally twice.
- No flow control or congestion control. UDP sends as fast as the application asks.
- Message boundaries are kept. One send produces one datagram, and the receiver reads it as one unit, as article 1 showed.
That sounds like a weakness, but it's why UDP is everywhere. DNS lookups, DHCP, video calls (RTP, the Real-time Transport Protocol), online games, WireGuard VPNs and QUIC, the transport under HTTP/3, all run over UDP. They pick UDP because they want to decide for themselves how to handle loss and timing, or because they need broadcast or multicast, which only a connectionless protocol can do. Cloudflare's 2025 measurements put HTTP/3, and therefore UDP, at about a fifth of all web requests it sees.
UDP is defined in RFC 768 from 1980, which is only three pages long and is Internet Standard STD 6. It was unchanged for 45 years until RFC 9868 (October 2025) defined optional UDP options, described later in this article.
Where UDP sits in a packet
A UDP datagram travels inside an IP datagram. The IPv4 Protocol field, or the IPv6 Next Header field, is 17 for UDP. Each send by the application normally produces exactly one UDP datagram, and so one IP datagram. That's a big difference from TCP, where what the application writes and what goes on the wire can be quite different.
For a 5-byte message over IPv4 with no options, the sizes are:
| Part | Bytes |
|---|---|
| IPv4 header | 20 |
| UDP header | 8 |
| Data | 5 |
| IPv4 total length | 33 |
Over IPv6 the IP header is 40 bytes instead of 20, so the same message is 53 bytes.
The UDP header
The header is always 8 bytes: four 16-bit fields.

- Source Port. The sender's port, where replies should go. It's optional: a sender that never expects a reply may set it to 0. In practice almost every UDP sender fills it in, because the operating system picks an ephemeral port automatically.
- Destination Port. The receiving program's port, such as 53 for DNS or 443 for QUIC. The receiving host uses it to deliver the datagram to the right socket.
- Length. The length of the UDP header plus data, in bytes. The minimum is 8, a datagram with no data, which is legal. The field is redundant, because IP already says how long its payload is. The receiver checks that the two agree. RFC 9868 now gives meaning to a UDP Length that's shorter than the IP payload: the extra bytes after the data are the UDP options area.
- Checksum. Covers the header, the data and a pseudo-header, described next. Over IPv4 a value of 0 means "no checksum computed". Over IPv6 a checksum is required.
UDP ports are separate from TCP ports. The IP layer first picks the transport protocol from the Protocol or Next Header field, and only then does that protocol look at ports. So UDP port 53 and TCP port 53 are two different endpoints, and two unrelated programs could use them. IANA usually registers a service on the same number for both protocols, but only for convenience.
A UDP exchange, captured
In the lab, a small server on server (198.51.100.10) listens on UDP port 9000 and replies with the data in upper case. The client on 192.0.2.10 sends hello:
reply: b'HELLO'
The server sees the client's address and its ephemeral port:
from 192.0.2.10 port 39007: b'hello'
The capture on the server, with tcpdump -vv:
IP (tos 0x0, ttl 63, id 26214, offset 0, flags [DF], proto UDP (17), length 33)
192.0.2.10.39007 > 198.51.100.10.9000: [udp sum ok] UDP, length 5
IP (tos 0x0, ttl 64, id 15730, offset 0, flags [DF], proto UDP (17), length 33)
198.51.100.10.9000 > 192.0.2.10.39007: [udp sum ok] UDP, length 5
Read it field by field:
- The first line of each packet is the IPv4 header:
tosis the type-of-service byte (DSCP and ECN, article 25),idthe IP Identification andoffsetthe fragment offset (both article 46). length 33is the IPv4 total length: 20 + 8 + 5.UDP, length 5is the data length that tcpdump computed from the UDP Length field (13) minus the 8-byte header.[udp sum ok]means tcpdump recomputed the checksum and it matched.flags [DF]: Linux sets Don't Fragment on UDP by default and does path MTU discovery. Article 47 explains why.ttl 63on the request: the client sent it with TTL 64, and routerr1decremented it.- There's no handshake and no acknowledgment. One datagram went each way, and that was the whole conversation.
How the checksum is computed
The UDP checksum uses the same algorithm as the IPv4 header checksum (article 24): add up the data as 16-bit words in one's complement arithmetic, then invert the result. Two details are specific to UDP and TCP.
1. The pseudo-header. Before summing, the sender prepends a pseudo-header built from IP-layer fields: the source and destination addresses, the protocol number and the UDP length. It's never transmitted. The receiver rebuilds it from the IP header that arrived and includes it in the check. The point is to catch datagrams that were delivered to the wrong host or handed to the wrong protocol: if the addresses were damaged in transit, the checksum fails even though the UDP bytes themselves are intact.

2. A virtual pad byte. The algorithm adds 16-bit words, but a UDP datagram can have an odd length. For the computation only, one zero byte is appended. It isn't sent.
Here's a real hello datagram from the lab, as hex. It comes from a second exchange, to port 9001, so its ports and IP ID differ from the capture above. The Ethernet header is the first 14 bytes, the IPv4 header the next 20, and the UDP datagram starts at offset 0x22:
0000 02 00 00 00 02 10 02 00 00 00 02 01 08 00 45 00 ..............E.
0010 00 21 74 71 40 00 3f 11 db 12 c0 00 02 0a c6 33 .!tq@.?........3
0020 64 0a a0 e1 23 29 00 0d 0b af 68 65 6c 6c 6f d...#)....hello
The UDP header is the 8 bytes a0 e1 23 29 00 0d 0b af: source port 0xa0e1 = 41185, destination port 0x2329 = 9001, length 0x000d = 13 and checksum 0x0baf. Then come the 5 data bytes, 68 65 6c 6c 6f, which is hello in ASCII. The UDP fields that tshark decoded from those bytes:
udp.srcport udp.dstport udp.length udp.checksum
41185 9001 13 0x0baf
A short Python script in the lab rebuilt the pseudo-header from the IP addresses in the capture and recomputed the checksum. The source and destination addresses (192.0.2.10 is c0 00 02 0a, 198.51.100.10 is c6 33 64 0a), a zero byte, protocol 11 (17) and length 00 0d (13) form the pseudo-header:
pseudo-header : c0 00 02 0a c6 33 64 0a 00 11 00 0d
UDP length : 13 bytes (8 header + 5 data)
16-bit words : 13 (one zero pad byte added: True)
folded sum : 0xf450
checksum : 0x0baf (one's complement of the sum)
in the packet : 0x0baf
Here is the sum by hand. The 13 words are the pseudo-header (c000 020a c633 640a 0011 000d), the UDP header with the checksum field set to 0 for the computation (a0e1 2329 000d 0000) and the data with its pad byte (6865 6c6c 6f00). They add up to 0x3f44d. Folding the carry back in gives 0xf44d + 0x3 = 0xf450, and inverting every bit gives 0x0baf.
The computed value matches the one in the packet. Notice that the 13-byte datagram needed the pad byte: 12 pseudo-header bytes plus 13 UDP bytes plus 1 pad byte give 26 bytes, or 13 words.
Two edge cases complete the rules:
- If the computed checksum is
0x0000, the sender transmits0xFFFFinstead. In one's complement arithmetic both represent zero, and0x0000on the wire is reserved to mean "no checksum". - The length appears twice in the sum: once in the pseudo-header and once in the UDP header itself. That's expected.
Zero and wrong checksums, tested
What does a receiver actually do with a missing or wrong checksum? In the lab, the client used Scapy to craft five datagrams to a dual-stack server socket on port 9000: three over IPv4 (correct checksum, checksum 0, wrong checksum) and two over IPv6 (correct checksum, checksum 0). The server program printed what it received:
received b'v4 correct checksum' from ::ffff:192.0.2.10
received b'v4 checksum zero' from ::ffff:192.0.2.10
received b'v6 correct checksum' from 2001:db8:1::10
(no more datagrams)
And the server's kernel counters (nstat -a) afterwards, each shown as a name, a count and a rate per second:
UdpInDatagrams 2 0.0
UdpInErrors 1 0.0
UdpInCsumErrors 1 0.0
Udp6InDatagrams 1 0.0
Udp6InErrors 1 0.0
Udp6InCsumErrors 1 0.0
The results match the rules exactly:
- IPv4, checksum 0: accepted. Over IPv4 a zero checksum means "the sender didn't compute one", and the receiver skips the check.
- IPv4, wrong checksum: silently discarded and counted in
UdpInCsumErrors. No ICMP error is sent and the application is never told. - IPv6, checksum 0: discarded and counted in
Udp6InCsumErrors. IPv6 has no header checksum, so UDP's checksum is the only check on the addresses. RFC 8200 makes it mandatory.
The IPv4 addresses appear as ::ffff:192.0.2.10 because the server used one IPv6 socket for both families. Article 48 explains these IPv4-mapped addresses.
Should anyone send zero checksums over IPv4 today? RFC 1122 requires hosts to compute UDP checksums by default and to verify them when present. Some vendors in the 1980s turned checksums off to speed up NFS (Network File System, for sharing files over a network), and corrupted files were the result: Ethernet's CRC only protects one link, and buggy routers and switches can damage data in memory between links. The one accepted exception is tunneling. RFC 6935 and RFC 6936 allow zero checksums over IPv6 for specific UDP tunnel protocols, because the tunneled packet carries its own checksum. VXLAN, which carries Ethernet frames inside UDP between data-center hosts, for example, may send zero checksums. Ordinary applications should never do it.
Why captures show "bad udp cksum" on the sender
If you capture on the machine that sends the traffic, you'll often see this, from the same lab with default settings:
IP (tos 0x0, ttl 64, id 25286, offset 0, flags [DF], proto UDP (17), length 33)
192.0.2.10.34006 > 198.51.100.10.9002: [bad udp cksum 0xec66 -> 0x27b9!] UDP, length 5
Nothing is broken. Modern network cards compute checksums in hardware, which is called checksum offload. The kernel leaves only the pseudo-header part of the sum in the field and hands the packet to the driver, and tcpdump copies the packet before the card fills in the real checksum. The interface shows offload enabled:
rx-checksumming: on
tx-checksumming: on
On the receiving side, or after turning offload off with ethtool -K eth0 tx off, the checksums are correct, as in the earlier capture. If you see "bad checksum" only on outgoing packets in Wireshark or tcpdump, it's almost certainly offload. Wireshark disables UDP checksum validation by default for exactly this reason.
Sending to a port nobody listens on
UDP has no handshake, so how does a sender learn that nothing is listening? The receiving host answers with an ICMP Destination Unreachable (Port Unreachable) message, which carries the start of the datagram that couldn't be delivered (article 40). In the lab, the client used a connected UDP socket, one where connect() fixed the peer address, and sent twice to port 9999, which nobody was listening on:
first send() succeeded
second send() failed: [Errno 111] Connection refused
The capture on the client shows the datagram and the ICMP reply:
IP 192.0.2.10.52303 > 198.51.100.10.9999: UDP, length 13
IP 198.51.100.10 > 192.0.2.10: ICMP 198.51.100.10 udp port 9999 unreachable, length 49
The first send() succeeded, because UDP only hands the datagram to IP and returns. When the ICMP error arrived, the kernel matched it to the connected socket and reported ECONNREFUSED on the next call. Two details are worth remembering:
- Only connected sockets get the error. An unconnected socket that uses
sendto()normally isn't told, because the kernel can't be sure which program the error belongs to. - Many firewalls drop the ICMP message. Then the sender sees nothing at all, which is indistinguishable from a lost datagram. That's why UDP applications need timeouts.
UDP options: the first change since 1980
RFC 9868 (October 2025) adds transport options to UDP without changing the header. It works because of the redundant length field: if the UDP Length field is smaller than the IP payload, the bytes after the data form a surplus area that can carry options, with their own checksum. Receivers that don't understand options just see the UDP Length and deliver the data, ignoring the surplus, so old software keeps working. Options can carry things like a maximum segment size, timestamps, authentication, and support for path MTU discovery and fragmentation done by UDP itself. Implementations are only starting to appear, so you won't see these options in ordinary traffic yet.
Common questions
Is UDP unreliable because it's badly designed?
No. It's minimal by design. UDP gives applications IP's best-effort delivery plus ports and a checksum, and lets them add exactly the reliability they need. QUIC, for example, builds its own retransmission, ordering per stream, and congestion control on top of UDP.
Why does UDP have a Length field if IP already gives the length?
Historically it was simply part of the design, and the receiver checks that the two agree. The redundancy turned out to be useful: RFC 9868 uses the difference between the IP length and the UDP Length to carry UDP options. With IPv6 jumbograms (packets over 65,535 bytes), the UDP Length is set to 0 and the real length comes from IPv6.
Can a UDP datagram have zero bytes of data?
Yes. A datagram with only the 8-byte header is legal and is delivered to the application as an empty message. Some protocols use empty datagrams as keepalives.
Does the UDP checksum protect against attackers?
No. It's a simple error-detecting code: anyone who changes the data can recompute the checksum. It catches accidental damage only. Integrity against attackers needs cryptography, such as DTLS (Datagram TLS, TLS adapted to UDP), QUIC's built-in TLS, or IPsec.
Is the UDP checksum strong enough on its own?
It catches all single-bit errors and most burst errors, but it misses some patterns, such as two 16-bit words swapped, or errors that cancel out. On most links the link layer's CRC catches far more. Protocols that care about integrity add their own stronger check, or use encryption, which detects any change.
If a datagram fails the checksum, does the sender find out?
No. The receiver discards it silently and only increments a counter. From the sender's point of view it's just a lost datagram. If the application needs delivery, it must notice the missing reply and send again.
Why did my capture show a different checksum than the program computed?
If you captured on the sending machine, checksum offload is the likely cause: the card fills in the checksum after tcpdump has already copied the packet. Capture on the receiver, or turn offload off on the sender for the test.
Can a UDP program learn the destination address a datagram was sent to?
Not from a normal recvfrom(), which only returns the sender's address. A server bound to all addresses can ask for it with the IP_PKTINFO (IPv4) or IPV6_RECVPKTINFO (IPv6) socket option. Article 48 shows why servers with several addresses need this.
Summary
- UDP adds only ports and a checksum to IP. It has no connections, reliability, ordering, flow control or congestion control, and it preserves message boundaries.
- The header is 8 bytes: source port (optional, may be 0), destination port, length (at least 8) and checksum. The protocol number is 17.
- UDP and TCP port spaces are independent: IP picks the protocol before ports are examined.
- The checksum is the one's complement of the one's complement sum over a pseudo-header (addresses, protocol, length), the UDP header and the data, with a virtual zero pad byte for odd lengths. A computed zero is sent as
0xFFFF. - Over IPv4 a zero checksum means "none" and is accepted. Over IPv6 the checksum is mandatory, and zero is dropped, except for specific tunnels under RFC 6936. Bad checksums are dropped silently and counted.
- "Bad checksum" on outgoing packets in a capture is usually checksum offload.
- A datagram to a closed port triggers ICMP Port Unreachable, which a connected socket reports as
ECONNREFUSEDon a later call. Firewalls often drop that ICMP message. - RFC 9868 (2025) adds UDP options in the surplus area after the data, using the gap between the IP and UDP lengths.
Practice questions
1. An application sends a 100-byte message over UDP and IPv6, with no extension headers. What are the UDP Length field and the IPv6 Payload Length?
Answer
UDP Length = 8 + 100 = 108. The IPv6 Payload Length counts everything after the 40-byte IPv6 header, which here is just the UDP datagram, so it's also 108. The whole packet is 148 bytes.
2. Why is the UDP checksum mandatory over IPv6 but optional over IPv4?
Answer
IPv4 has a header checksum that protects the addresses, so even without a UDP checksum a damaged address is likely to be caught. IPv6 removed the header checksum, so UDP's checksum, through its pseudo-header, is the only end-to-end check that the datagram reached the right host and protocol.
3. A sender computes a UDP checksum of 0x0000. What does it put in the header, and why?
Answer
0xFFFF. In one's complement arithmetic, 0x0000 and 0xFFFF both represent zero, so the checksum is still valid. The value 0x0000 on the wire is reserved to mean "no checksum computed", so a real computed zero must be sent as 0xFFFF.
4. A NAT device changes a UDP datagram's source address from 192.0.2.10 to 203.0.113.5 and its source port. Which checksums must it update?
Answer
Both the IPv4 header checksum (the source address is in the IP header) and the UDP checksum, because the source address is part of the pseudo-header and the source port is in the UDP header. If the UDP checksum was 0, meaning none, it can stay 0.
5. A program sends a datagram with sendto() on an unconnected socket to a closed port, and the call returns success. Has the datagram been delivered?
Answer
No. sendto() returning success only means the datagram was handed to IP for sending. UDP has no acknowledgments. The receiving host will answer with ICMP Port Unreachable, but an unconnected socket usually isn't told about it, and a firewall may drop the ICMP message anyway.
6. You capture traffic on a sending server and see [bad udp cksum 0x1c2e -> 0x8f01!] on every outgoing datagram, but clients receive the data fine. What's happening?
Answer
Checksum offload. The kernel leaves a partial value (the pseudo-header sum) in the checksum field and the network card computes the real checksum as the packet leaves. tcpdump sees the packet before the card finishes. Capture on the receiver, or disable offload with ethtool -K <interface> tx off, to see correct checksums.
7. Why does the pseudo-header include the protocol number?
Answer
So that a datagram meant for one transport protocol and handed to another, for example because the Protocol field was damaged, fails the checksum. TCP and UDP use the same algorithm and similar pseudo-headers, and the protocol number (6 or 17) is what makes their sums differ.
Previous: IGMP and MLD: Joining Multicast Groups, Queriers and Snooping
Next: IP Fragmentation and Reassembly: How It Works and Why It's Avoided

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.