Blog/Category
Shipping Tips & Tricks

How to Calculate Dimensional Weight and USPS Cubic Pricing in Code

December 1, 2026
Founder and CEO
How to Calculate Dimensional Weight and USPS Cubic Pricing in Code

Updated December 2026. Codes and rules verified against carrier documentation; see references at the end.

To calculate USPS dimensional weight in code, round each side up to the next whole inch, multiply length by width by height, and if the result is over 1,728 cubic inches, divide by 139 and round up to the next pound. UPS uses the same 139 divisor for Daily Rates (166 for domestic Retail Rates), but it rounds each side to the nearest inch and applies DIM weight at any size. The billable weight is the greater of actual and DIM weight. USPS cubic pricing is a separate calculation: round each side down to the nearest 1/4 inch, convert to cubic feet, and bucket into 0.1 cubic foot tiers.

What are the USPS dimensional weight rules in 2026?

The rules below took effect July 12, 2026. They are the same in DMM 223 (Priority Mail commercial), 283 (USPS Ground Advantage commercial), 213 (Priority Mail Express), 253 (Parcel Select) and the retail sections 113, 123 and 133.

  1. Measure length, width and height in inches. Round each measurement up to the next whole inch (12.1 becomes 13).
  2. Multiply the three rounded sides.
  3. If the result exceeds 1,728 cubic inches (1 cubic foot), divide by 139 and round up to the next whole pound. At 1,728 or below, DIM weight does not apply.
  4. For a nonrectangular parcel, multiply the volume by 0.785 before the 1,728 check and the division.
  5. If DIM weight exceeds 70 pounds, you pay the 70-pound price.

Actual weight is rounded up to the next whole pound for Priority Mail. USPS Ground Advantage commercial prices under 1 pound use 4, 8, 12 and 15.999 ounce increments, so the pound-based billable function below applies to packages of 1 pound and up.

One inconsistency: as of December 2026, DMM 223.1.4.3 (Priority Mail commercial, nonrectangular) still reads "round off" and divisor 166. Check it before you hard-code nonrectangular Priority Mail.

How does UPS calculate dimensional weight?

UPS measures each side at its longest point and rounds to the nearest whole inch (1.00 to 1.49 becomes 1, 1.50 to 1.99 becomes 2), with a 1 inch minimum per side. Multiply the sides, divide by 139 (Daily Rates) or 166 (domestic Retail Rates; the Retail guide uses 139 for exports), and round any fraction up to the next pound. Actual weight also rounds up to the next pound, and billable weight is the greater of the two. UPS says DIM weight may apply to all domestic and international package services, with no 1 cubic foot threshold, so a small, light box can still bill on DIM weight. The "How to measure" section of the same UPS page says to round each side up (1.01 becomes 2), which conflicts with its DIM formula and the Rate and Service Guide. The code follows the guide; round up instead for a conservative estimate.

How do USPS and UPS DIM rules differ?

RuleUSPS (from July 12, 2026)UPS
Side roundingUp to next whole inchNearest whole inch (.50 rounds up), minimum 1 inch
When DIM appliesVolume over 1,728 cu inAny package
Divisor139139 Daily Rates, 166 domestic Retail Rates
NonrectangularVolume x 0.785Measure at extreme points as if in a rectangular box
Result roundingUp to next poundUp to next pound
CapDIM over 70 lb pays the 70 lb priceNone stated; 150 lb max actual weight

How do I calculate DIM weight in Python?

Use exact arithmetic so float noise never pushes a side over an inch boundary. Python's built-in round() uses banker's rounding (round(12.5) is 12), which is wrong for UPS, so the code rounds half up explicitly.

from fractions import Fraction as F
import math

def _f(x):
    return F(str(x))          # exact: 12.1 -> 121/10

def _half_up(x):
    return math.floor(x + F(1, 2))   # UPS "nearest inch"; not round()

def usps_dim_weight(l, w, h, nonrectangular=False):
    dims = [math.ceil(_f(d)) for d in (l, w, h)]   # round UP to whole inch
    vol = F(dims[0] * dims[1] * dims[2])
    if nonrectangular:
        vol *= F(785, 1000)
    if vol <= 1728:
        return None                                # DIM does not apply
    return min(math.ceil(vol / 139), 70)           # 70 lb price cap

def usps_billable_lb(actual_lb, l, w, h, nonrectangular=False):
    dim = usps_dim_weight(l, w, h, nonrectangular)
    return max(math.ceil(_f(actual_lb)), dim or 0)

def ups_dim_weight(l, w, h, divisor=139):          # 166 for Retail Rates
    dims = [max(1, _half_up(_f(d))) for d in (l, w, h)]
    return math.ceil(F(dims[0] * dims[1] * dims[2]) / divisor)

def ups_billable_lb(actual_lb, l, w, h, divisor=139):
    return max(math.ceil(_f(actual_lb)), ups_dim_weight(l, w, h, divisor))

How do I calculate DIM weight in JavaScript?

JavaScript has no exact decimal type, so convert inches to hundredths and keep the comparisons in integers. Billable weight is then Math.max(Math.ceil(actualLb), dim ?? 0), as in the Python version.

const hundredths = (x) => Math.round(x * 100); // assumes input to 0.01 inch
const ceilDiv = (a, b) => Math.floor((a + b - 1) / b); // integers only

export function uspsDimWeight(l, w, h, { nonrectangular = false } = {}) {
  const [a, b, c] = [l, w, h].map((d) => ceilDiv(hundredths(d), 100));
  let vol = a * b * c;
  if (nonrectangular) vol = (vol * 785) / 1000;
  if (vol <= 1728) return null;
  return Math.min(Math.ceil(vol / 139 - 1e-9), 70);
}

export function upsDimWeight(l, w, h, divisor = 139) {
  const [a, b, c] = [l, w, h].map((d) =>
    Math.max(1, Math.floor((hundredths(d) + 50) / 100))); // .50 rounds up
  return ceilDiv(a * b * c, divisor);
}

What do these functions return for real box sizes?

Produced by running the functions above; Python and JavaScript gave identical results.

Box (inches), actual weightUSPS DIMUSPS billableUPS DIM (139)UPS DIM (166)UPS billable (139)
12 x 12 x 12, 4 lbnone (exactly 1,728)4131113
12 x 12 x 12.1, 4 lb1414131113
14 x 10 x 8, 2.2 lbnone3979
18 x 14 x 12, 6 lb2222221922
16.4 x 12.6 x 10.5, 3 lb1818171417
24 x 18 x 18, 10 lb5656564756
36 x 24 x 24, 15 lb70 (capped)70150125150

In the 12 x 12 x 12.1 row, USPS rounds 12.1 up to 13 (1,872 cu in) while UPS rounds it to 12 (1,728 cu in). A nonrectangular 20 x 20 x 10 parcel at USPS is 4,000 x 0.785 = 3,140 cu in, or 23 lb.

How do you calculate the USPS cubic tier in code?

Per DMM 223.1.3 and 283.1.3:

  • Round each side down to the nearest 1/4 inch (6-1/8 becomes 6, 12-3/8 becomes 12-1/4).
  • Multiply the sides and divide by 1,728 to get cubic feet.
  • Tiers are "up to and including" each 0.1: 0.125 cubic feet is tier 0.2.
  • Limits: weight 20 lb or less, longest side 22 inches or less, no rolls or tubes. Priority Mail cubic tops out at 0.50 cubic foot (5 tiers). USPS Ground Advantage commercial cubic goes to 1 cubic foot (10 tiers).
  • Soft packs and padded envelopes use length plus width instead, each rounded down to 1/4 inch, with a 36-inch maximum and the same 22-inch longest-side limit: up to 21 in is 0.10, over 21 to 27 is 0.20, over 27 to 31 is 0.30, over 31 to 34 is 0.40, over 34 to 36 is 0.50.
from fractions import Fraction as F
import math

CUBIC_MAX = {"priority": F(1, 2), "ground_advantage": F(1)}

def quarter_down(x):
    return F(math.floor(F(str(x)) * 4), 4)       # 12.375 -> 12.25

def usps_cubic_tier(l, w, h, weight_lb, product="priority"):
    s = sorted((quarter_down(d) for d in (l, w, h)), reverse=True)
    if s[0] > 22 or F(str(weight_lb)) > 20:
        return None
    cuft = s[0] * s[1] * s[2] / 1728
    if cuft > CUBIC_MAX[product]:
        return None
    return max(F(math.ceil(cuft * 10), 10), F(1, 10))   # 0.1 steps; float() for display

def usps_soft_pack_tier(length, width):           # also check weight <= 20 lb
    l, w = quarter_down(length), quarter_down(width)
    if max(l, w) > 22:
        return None                                # longest side over 22 in
    total = l + w
    for limit, tier in [(21, "0.1"), (27, "0.2"), (31, "0.3"), (34, "0.4"), (36, "0.5")]:
        if total <= limit:
            return tier
    return None                                    # over 36 in: not cubic

Cubic test table

Box (inches), weightPriority Mail tierGround Advantage tier
6-1/8 x 5-7/8 x 6-3/8, 2 lb (DMM's own example)0.20.2
8 x 6 x 4, 1 lb0.20.2
10 x 8 x 6, 3 lb0.30.3
12 x 10 x 6, 5 lb0.50.5
12 x 12 x 8, 8 lbnot eligible (over 0.5)0.7
12 x 12 x 12, 15 lbnot eligible1.0
23 x 6 x 6, 4 lbnot eligible (side over 22)not eligible
10 x 8 x 6, 21 lbnot eligible (over 20 lb)not eligible

Soft packs from the same run: 10 x 13 is tier 0.2, 12 x 15.5 is 0.3, 14.5 x 19 is 0.4, 10-1/8 x 10.9 (10 + 10.75 = 20.75) is 0.1, and 19 x 19 (over 36) and 23 x 10 (side over 22) are not eligible.

In the USPS Domestic Prices API v3, cubic results come back with rate indicators such as C1 to C5 (Cubic Pricing Tier 1 to 5), CP (Cubic Parcel) and P5 to P9 (Cubic Soft Pack Tier 1 to 5). In the Labels API, the matching packagingType values are CUBIC_PARCELS and CUBIC_SOFT_PACK.

When does a USPS package get a nonstandard fee?

Priority Mail (DMM 223.1.10) and USPS Ground Advantage commercial (DMM 283.1.7) charge nonstandard fees for:

  • Length over 22 inches up to 30 inches.
  • Length over 30 inches.
  • Volume over 2 cubic feet (3,456 cu in). This check rounds each side off to the nearest inch, which is different from the round-up rule used for DIM weight. Nonrectangular volume is multiplied by 0.785.
  • Nonstandard characteristics listed in DMM 201.7.6.2.

A length fee and a cube fee can both apply: 24 x 18 x 18 triggers both.

What are the size and weight limits?

LimitUSPSUPS
Max weight70 lb150 lb actual weight
Max size108 in length plus girth; 130 in for Ground Advantage, Parcel Select Destination Entry and USPS Connect Local165 in length plus girth; 108 in max length
Oversized / large packageGround Advantage and Parcel Select oversized price over 108 in up to 130 inLarge Package: length plus girth over 130 in or length over 96 in, with a minimum billable weight (see the current UPS Rate and Service Guide)

Frequently asked questions

Do I need to calculate DIM weight myself if I use the carrier API?

Not for the final rate. The USPS Domestic Prices API v3 takes dimensions and uses the greater of DIM and actual weight. Local functions help with box selection, checkout estimates and spotting nonstandard fees early.

Is the USPS DIM divisor 139 or 166?

139 for rectangular parcels in every 2026 DMM section. 166 appears only in the nonrectangular rule of DMM 223.1.4.3 for Priority Mail commercial, which still shows the older text as of December 2026.

Can a package use both cubic pricing and DIM weight?

They are separate price structures: cubic is priced by tier and zone, weight-based by billable weight and zone. Because cubic rounds sides down and DIM rounds them up, a 12 x 12 x 12.1 box under 20 lb is tier 1.0 for Ground Advantage cubic but 14 lb DIM by weight. Quote both and buy the lower one.

More shipping developer references

Build shipping with Ship.com

Ship.com gives you USPS and UPS labels at up to 89% off USPS and up to 87% off UPS without your own carrier accounts, from your code through the REST API or from AI agents through the MCP server. Every account starts with a 30-day free trial, no credit card required. Read the Ship MCP setup guide or See plans and pricing.

Related reading: USPS dimensional weight rules for 2026, USPS cubic pricing explained, and the Ship.com shipping calculator.

References

Joe DiSorbo
About the author
Joe DiSorbo
Founder and CEO

Joe DiSorbo is the founder and CEO of Ship.com, the shipping platform that gives more than 10,000 business customers discounted USPS and UPS rates and simplifies logistics for ecommerce brands and software platforms. Before Ship.com, he founded and led Webgistix, an ecommerce technology and global fulfillment company that grew internationally before Rakuten acquired it in 2013. His background spans global operations, software development, finance and logistics, with experience across the United States and Asia. Joe holds undergraduate degrees in Economics and Geography, masters degrees in Finance and International Management, and is a graduate of Harvard Business School (OPM 41).

Shipping software built for online sellers

Ship.com saves you time and money, giving you more freedom to live your life.

  • No credit card required.
  • Up to 89% off USPS and up to 87% off UPS.
  • Connects with major e-commerce platforms.
  • Free home pickup. Skip the trip to the post office.
Try for free
UPS
UP TO 87% OFF
Daily Rates*
USPS
UP TO 89% OFF
Retail Prices*
Today's orders
Order #1042USPS Ground AdvantageReady
Order #1043UPS Ground SaverReady
Order #1044USPS Priority MailReady
★★★★★Trusted by 10,000+ business customers

More on this topic

See all