Experiments and implementations · Intermediate

Exploring MTU and packet-size relationships

Calculate header-inclusive budgets and distinguish application writes, IP packet size and path MTU.

Ask Logeia about this articleTry the three questionsReview your answers

Updated

On this page
  1. Choose the layer whose length is counted
  2. State IPv4 and IPv6 assumptions
  3. Test the one-byte boundary
  4. A TCP write is not a packet boundary
  5. Investigate path MTU separately
  6. Carry the model into diagnosis carefully
  7. Ask Logeia about this articleCheck your understanding

Choose the layer whose length is counted

An application’s supplied bytes and the total IP packet length are different quantities. This small model computes payload budgets from fixed IP and UDP or TCP header sizes. It does not send large packets onto a network. Separate the executable Python arithmetic from any later investigation of a real path. Fifteen hundred bytes is an input assumption, not a universal network constant. Changing interfaces or introducing a tunnel requires identifying the relevant MTU boundary again. The model is useful because its counted layers are explicit, not because every device or route necessarily uses the same numbers.

State IPv4 and IPv6 assumptions

Assume a twenty-byte base IPv4 header and eight-byte UDP header. An MTU of fifteen hundred then leaves 1,472 payload bytes. In a separate IPv6 example, a forty-byte base header and eight-byte UDP header with MTU 1,280 leave 1,232 bytes. IPv4 options and IPv6 extension headers are excluded from this simplified calculation. Encryption or encapsulation can introduce more overhead at the relevant boundary. Writing the subtraction and its layer assumptions is more useful than memorizing a single payload number. It also makes clear when an apparently familiar value no longer applies to a different packet format.

Test the one-byte boundary

The assertions show that a 1,472-byte payload plus the assumed IPv4 and UDP headers fits fifteen hundred, whereas one extra byte exceeds it. The TCP calculation assumes a twenty-byte header without options and produces 1,460, but this is a budget rather than an observed segment length. Invalid inputs whose headers exceed the MTU raise an error instead of returning a meaningless negative payload. When substituting another MTU, record IP version and overhead assumptions together. A correct arithmetic operation can still answer the wrong networking question if its inputs come from incompatible layers or configurations.

Python 3
def payload_budget(mtu, ip_header, transport_header):
    if mtu < ip_header + transport_header:
        raise ValueError("headers exceed MTU")
    return mtu - ip_header - transport_header
v4_udp = payload_budget(1500, 20, 8)
v6_udp = payload_budget(1280, 40, 8)
assert v4_udp == 1472 and v6_udp == 1232
assert 1472 + 20 + 8 <= 1500
assert 1473 + 20 + 8 > 1500
# IPv4 TCP without options: this is a header budget, not observed segment size.
assert payload_budget(1500, 20, 20) == 1460
print({"IPv4_UDP": v4_udp, "IPv6_UDP": v6_udp, "IPv4_TCP_no_options": 1460})

A TCP write is not a packet boundary

One large TCP write does not necessarily produce one equally large IP packet. TCP exposes a byte stream and can divide or combine supplied data into segments. MSS concerns TCP payload, while MTU concerns the relevant packet boundary. The calculated 1,460 here assumes only particular base headers. Packet captures can also be affected by offload facilities, so a host-visible buffer may differ from packets transmitted on the wire. If extending this model into a capture experiment, record the observation point and offload conditions. Do not infer an invalid network MTU solely from one unexpectedly large host capture record.

Investigate path MTU separately

An interface MTU need not equal the limiting size across an entire path. IPv4 handling depends on fragmentation-related conditions such as DF, while IPv6 routers do not fragment packets in transit. Sender discovery of a usable path size and delivery of appropriate error information consequently matter. A failed size probe alone, however, does not prove an MTU problem: filtering, loss and destination response policy are alternative explanations. Use an authorized test path if extending to actual traffic, and document probe conditions and competing explanations. This arithmetic program does not itself observe path discovery, fragmentation or delivery failures.

Carry the model into diagnosis carefully

Record MTU, base IP header, transport header, extra overhead and computed payload separately. Do not combine UDP datagram sizes, TCP write sizes and captured buffer lengths into one ambiguously named measurement. Successful execution validates the subtraction and boundary checks, not reachability over an Internet path. For a symptom where only large responses stall, also identify progress through resolution, connection, TLS, request transmission and response. A size correlation is a useful clue but not proof of one cause. The model supplies a disciplined vocabulary for that investigation while leaving actual path behavior to separately designed observations.

Reading and practice are recorded separately in this browser, for each language.

Learn this in order

Understand the systems behind the web · STEP 10

Choose a learning path