What is the largest payload a single UDP datagram can carry over IPv4 and over IPv6, and where do those numbers come from?
answer
- 16-bit length fields everywhere
- subtract the headers that count
- IPv4 total length includes its header
- IPv6 payload length excludes its header
- 65,507 and 65,527
basics
~20 sOver IPv4 the maximum is 65,507 bytes: a 65,535-byte total length minus the 20-byte IPv4 header and 8-byte UDP header. Over IPv6 it is 65,527 bytes, because the 16-bit Payload Length excludes the IPv6 header; jumbograms aside.
solid answer
~40 sEvery length involved is a 16-bit field, so 65,535 is the ceiling. Over IPv4 the `Total Length` field counts the IP header too, so the UDP payload is 65,535 minus the minimum 20-byte IPv4 header minus the 8-byte UDP header: **65,507** bytes, and less if IP options are present. Over IPv6 the `Payload Length` field counts only what follows the 40-byte fixed header, so the limit is 65,535 minus 8: **65,527** bytes, less if extension headers are present. RFC 8085 quotes both numbers. IPv6 jumbograms (RFC 2675) can exceed this when every link supports them. These are protocol ceilings, not practical sizes: a datagram that large needs dozens of IP fragments on a 1500-byte MTU path.
go deeper
Remember the two numbers, 65,507 over IPv4 and 65,527 over IPv6, and that both come from 16-bit length fields.
Walk through the subtraction and explain why IPv4 Total Length includes its header while IPv6 Payload Length does not; mention that options and extension headers lower both limits.
Separate the protocol ceiling from the practical size: compute the 1,472-byte single-packet payload on a 1500-byte MTU and explain why RFC 8085 says not to exceed the path MTU.
Use the gap between ceiling and path MTU to argue message-size policy for a UDP protocol, including when the 576 or 1280-byte fallback is the right default.
## Three 16-bit length fields The maximum UDP payload is a subtraction problem, and the only thing that makes it tricky is knowing **which length field counts which headers**. Three fields are involved, and each is 16 bits wide, so none can exceed **65,535**: | Field | Where | What it counts | |---|---|---| | UDP `Length` | UDP header (RFC 768) | UDP header (8 bytes) plus data | | IPv4 `Total Length` | IPv4 header | IPv4 header plus everything after it | | IPv6 `Payload Length` | IPv6 header (RFC 8200) | everything after the 40-byte fixed header, extension headers included | A UDP datagram always travels in exactly one IP packet (fragmentation may split that packet in transit, but it is reassembled into one before UDP sees it), so the tightest of these limits wins. ## The IPv4 arithmetic 1. IPv4 `Total Length` is at most 65,535 bytes and **includes the IPv4 header**. 2. The minimum IPv4 header is **20 bytes** (RFC 6691 and RFC 1122 both use this figure). 3. The UDP header is **8 bytes**. 4. 65,535 − 20 − 8 = **65,507 bytes** of UDP payload. If the sender includes IPv4 options, the IP header grows and the ceiling falls by the same amount. The UDP `Length` field could in principle say 65,535, but the IPv4 packet around it could not hold that much, so the IP limit is the binding one. ## The IPv6 arithmetic 1. IPv6 `Payload Length` is at most 65,535 bytes and **excludes the 40-byte fixed header**. 2. With no extension headers, the whole payload is the UDP datagram, so UDP `Length` can reach 65,535. 3. 65,535 − 8 = **65,527 bytes** of UDP payload. Extension headers count inside `Payload Length`, so each one present reduces the UDP ceiling. RFC 8085 §1 states both results: "limited to a maximum payload of 65,507 bytes for IPv4 and 65,527 bytes for IPv6." ## Jumbograms IPv6 defines **jumbograms** (RFC 2675, cited by RFC 8085) for packets larger than 65,535 bytes when every link on the path supports them. They depend on every link along the path, so they are not a general answer; the working answer to the interview question is 65,507 and 65,527, "jumbograms aside". ## Why the ceiling is not the working size The numbers above are what the headers can express, not what a network will carry in one piece: - A typical Ethernet path has a **1500-byte MTU** (RFC 1191 lists it for Ethernet), so a single unfragmented IPv4 packet carries at most 1500 − 20 − 8 = **1,472 bytes** of UDP payload, and IPv6 at most 1500 − 40 − 8 = **1,452**. - A maximum-size IPv4 datagram (65,515 bytes of IP payload) would need about **45 fragments** on such a path, since each fragment holds at most 1,480 bytes of it. - RFC 8085 §3.2 says an application SHOULD NOT send datagrams whose IP packets exceed the path MTU, because losing any one fragment loses the whole datagram and some middleboxes drop fragments outright. - An application that does not know the path MTU SHOULD stay below the effective MTU for sending: the smaller of 576 bytes and the first-hop MTU for IPv4, and 1280 bytes for IPv6 (RFC 8085 §3.2). How IP splits and reassembles the packet, and how a sender discovers the path MTU, belong to IP fragmentation and Path MTU Discovery, not to UDP. ## Common mistakes - Answering **65,535** for the payload: that is the whole 16-bit field, headers included. - Answering **65,515** for IPv4: that forgets the UDP header. - Using the same number for both IP versions: the two IP length fields count different things, which is exactly where the 20-byte difference comes from. - Treating the ceiling as a safe size: a datagram that is legal by the header can still be unreliable on the path.
- Why is the IPv6 maximum UDP payload 20 bytes larger than the IPv4 one, even though the IPv6 header is bigger?Because the two IP length fields count different things. IPv4 `Total Length` includes the IPv4 header, so the 20-byte header comes out of the 65,535. IPv6 `Payload Length` counts only what follows the 40-byte fixed header, so the header costs nothing against the limit and only UDP's 8 bytes are subtracted.
- What is the largest UDP payload that fits in one unfragmented IPv4 packet on a 1500-byte MTU path?1,472 bytes: 1,500 minus the 20-byte minimum IPv4 header minus the 8-byte UDP header. RFC 8085 §3.2 tells applications to subtract the IP header, including any options or extension headers, and the 8-byte UDP header from the path MTU. Over IPv6 the same path allows 1,452 bytes.
saying these in an interview costs you the question
- The maximum UDP payload is 65,535 bytes on any IP version
- IPv4 and IPv6 give the same maximum UDP payload
- The IPv6 limit is smaller because its header is 40 bytes
- A 60 KB UDP datagram crosses the internet as one packet
- The maximum payload over IPv4 is 65,515 bytes