If you sell physical products online, there is one shipping rule that quietly eats margins: dimensional weight (DIM weight). A 3 lb pillow can be billed as if it weighed 16 lb, just because of the box it ships in.
I build free calculators for Etsy, eBay and Shopify sellers at DailyToolLab, and the Shipping Package Size Helper turned out to be one of the trickier small tools to get right. The maths is simple. The edge cases are where the bugs hide: rounding, thresholds, unit conversion and floating point.
This post walks through the USPS rules and a small JavaScript implementation you can drop into your own project.
The rule, straight from USPS
From the USPS Ground Advantage page (checked December 2026):
- Dimensional weight pricing applies when a package is larger than 1 cubic foot (1,728 cubic inches).
- Multiply length x width x height and divide by 139 to get DIM weight in pounds.
- Any fraction of an inch is rounded up to the next whole inch (12.2 in counts as 13 in).
- If the DIM weight is greater than the actual weight, you pay the DIM weight price.
USPS Postal Bulletin 22705 describes the July 12, 2026 change that set the divisor to 139 for Priority Mail Express, Priority Mail and USPS Ground Advantage, and switched dimension rounding to "round up". So if you have an older calculator hard-coded with 166, or one that rounds to the nearest inch, it is now out of date.
The billable weight is then:
billable = max(actualWeight, dimWeight) // both rounded up to whole pounds Step 1: normalise units before anything else
Users type centimetres, inches, grams, ounces, kilograms. Convert everything to inches and pounds first, then apply carrier rules. Mixing the two steps is the most common source of wrong answers.
const CM_PER_IN = 2.54; const LB_PER = { lb: 1, oz: 1 / 16, kg: 2.20462262, g: 0.00220462262 }; function toInches(value, unit) { return unit === "cm" ? value / CM_PER_IN : value; } function toPounds(value, unit) { const factor = LB_PER[unit]; if (factor === undefined) throw new Error(`Unknown weight unit: ${unit}`); return value * factor; } Step 2: round up, but carefully
USPS says to round each dimension up. Math.ceil looks like the obvious answer, but floating point can bite you. A value that should be exactly 12 after a unit conversion can come out as something like 12.000000000000002, and Math.ceil will happily turn that into 13. One extra inch on one side can push a box over the 1,728 in³ threshold and change the price.
A small tolerance fixes that:
const EPS = 1e-9; function ceilSafe(x) { return Math.ceil(x - EPS); } ceilSafe(12.2); // 13 (real fraction, rounds up) ceilSafe(12.000000000000002); // 12 (float noise, ignored) The same helper is used later for rounding DIM weight up to whole pounds.
Step 3: the threshold is "larger than", not "at least"
This is the edge case I see wrong most often. A 12 x 12 x 12 inch box is exactly 1,728 in³. The USPS wording is larger than 1 cubic foot, so that exact cube is normally priced on actual weight. Use >, not >=.
const USPS_DIVISOR = 139; const USPS_THRESHOLD_IN3 = 1728; function uspsDimWeight(lengthIn, widthIn, heightIn) { const l = ceilSafe(lengthIn); const w = ceilSafe(widthIn); const h = ceilSafe(heightIn); const volume = l * w * h; if (volume <= USPS_THRESHOLD_IN3) { return { volume, dimLb: null, applies: false }; } return { volume, dimLb: ceilSafe(volume / USPS_DIVISOR), applies: true }; } Step 4: put it together
function billableWeight({ length, width, height, dimUnit = "in", weight, weightUnit = "lb" }) { const dims = [length, width, height].map((v) => toInches(Number(v), dimUnit)); if (dims.some((v) => !Number.isFinite(v) || v <= 0)) { throw new Error("Dimensions must be positive numbers"); } const actualLb = toPounds(Number(weight), weightUnit); const dim = uspsDimWeight(...dims); const actualRounded = ceilSafe(actualLb); const billableLb = dim.applies ? Math.max(actualRounded, dim.dimLb) : actualRounded; return { volumeIn3: dim.volume, actualLb: actualRounded, dimLb: dim.dimLb, billableLb, billedOnDim: dim.applies && dim.dimLb > actualRounded, }; } A note on actualRounded: label tools typically price these services in whole-pound steps, so rounding actual weight up keeps the comparison apples to apples. Check how your own label software displays it.
Testing with known examples
These are the cases I keep as regression tests, worked by hand:
// Exactly 1 cubic foot: DIM does not apply billableWeight({ length: 12, width: 12, height: 12, weight: 3 }); // -> { volumeIn3: 1728, dimLb: null, billableLb: 3, billedOnDim: false } // One inch more per side: 2,197 in3 / 139 = 15.81 -> 16 lb billableWeight({ length: 13, width: 13, height: 13, weight: 3 }); // -> { volumeIn3: 2197, dimLb: 16, billableLb: 16, billedOnDim: true } // Big light carton: 3,024 in3 / 139 = 21.76 -> 22 lb billableWeight({ length: 18, width: 14, height: 12, weight: 4 }); // -> { volumeIn3: 3024, dimLb: 22, billableLb: 22, billedOnDim: true } // Fractions round up first: 12.2 x 12 x 12 -> 13 x 12 x 12 = 1,872 in3 billableWeight({ length: 12.2, width: 12, height: 12, weight: 2 }); // -> { volumeIn3: 1872, dimLb: 14, billableLb: 14, billedOnDim: true } That last one surprises people: two tenths of an inch turns a 2 lb parcel into a 14 lb one. That is exactly the kind of thing a calculator should surface.
Other carriers and metric couriers
Keep the carrier rules in data, not in if statements, so you can add more without touching the core logic. UPS and FedEx daily rates commonly use 139 too, but often without the 1 ft³ threshold. Metric couriers usually express it as cm³ per kg, commonly 5000 or 6000:
const CARRIERS = { usps: { divisor: 139, thresholdIn3: 1728, unit: "imperial" }, upsFdx: { divisor: 139, thresholdIn3: 0, unit: "imperial" }, metric5000: { divisor: 5000, threshold: 0, unit: "metric" }, }; // 40 x 30 x 20 cm = 24,000 cm3 / 5000 = 4.8 kg Account contracts and retail counters can differ (some still show 166), so in the UI I let the user pick the divisor and show a note telling them to match whatever their label software uses.
UX lessons from shipping this tool
- Show the volume and the rounded dimensions, not just the final number. Users trust a result they can check.
- Explain *why* when DIM wins ("billed on 16 lb because the box is 2,197 in³"). It turns a frustrating number into an actionable one: use a smaller box.
- Say what it is not. It is an estimate, not a live postage quote. Rates and rules change, so link to the official source.
- Keep it client-side. There is no reason to send box sizes to a server; everything above runs in the browser instantly.
If you want the seller-facing version of all this, with Flat Rate box sizes and when Flat Rate beats calculated shipping, I wrote it up here: USPS dimensional weight explained.
Sources: USPS Ground Advantage page (usps.com/ship/ground-advantage.htm) and USPS Postal Bulletin 22705. Always confirm current rules in your label software.


