The longest straight line that fits inside a rectangular box is its space diagonal: the line from one corner to the opposite corner. Calculating it requires extending Pythagoras's two-dimensional theorem into three dimensions — a small but elegant generalization that solves real-world problems.

The formula

d = √(l² + w² + h²)

For a box with length 5, width 3, and height 4:

d = √(25 + 9 + 16) = √50 ≈ 7.07

Whatever unit you measured in, that's the unit of the diagonal.

Where the formula comes from

Start with the standard Pythagorean theorem. For a right triangle with legs a and b and hypotenuse c:

c² = a² + b²

Now consider a rectangular box. Look at the bottom face — a rectangle with sides l and w. The diagonal of this bottom face is:

d_floor = √(l² + w²)

Now imagine the space diagonal: it goes from one bottom corner up to the opposite top corner. This forms the hypotenuse of a right triangle where:

  • One leg is the floor diagonal: √(l² + w²)
  • The other leg is the height: h

Apply Pythagoras again:

d_space² = d_floor² + h²
d_space² = (l² + w²) + h²
d_space = √(l² + w² + h²)

Pythagoras applied twice. The result generalizes: in n dimensions, the diagonal of a rectangular box is the square root of the sum of squared sides.

Worked examples

A standard moving box

An 18 × 14 × 10 inch moving box:

d = √(18² + 14² + 10²) = √(324 + 196 + 100) = √620 ≈ 24.9 inches

You can fit something just under 25 inches long, as long as it's thin enough to angle from corner to corner.

A 40-foot shipping container

40 ft long, 8 ft wide, 8.5 ft tall:

d = √(40² + 8² + 8.5²) = √1,736.25 ≈ 41.7 feet

So a 41-foot pole can fit diagonally in a 40-foot container.

A coffin

Roughly 84 × 28 × 23 inches:

d = √(84² + 28² + 23²) = √8,369 ≈ 91.5 inches

The kind of math undertakers actually do.

Calculate the diagonal of your box.
Open calculator →

Face diagonal vs space diagonal

A rectangular box has two kinds of diagonals:

  • Face diagonals are the diagonals across each rectangular face. Six in total.
  • Space diagonals go from corner to opposite corner through the interior. Four in total, all the same length.
Diagonal typeFormulaFor a 5 × 3 × 4 box
Face diagonal (l × w face)√(l² + w²)√34 ≈ 5.83
Face diagonal (l × h face)√(l² + h²)√41 ≈ 6.40
Face diagonal (w × h face)√(w² + h²)√25 = 5.00
Space diagonal√(l² + w² + h²)√50 ≈ 7.07

The space diagonal is always longer than any face diagonal.

Practical application: will it fit?

  1. Measure the item's length.
  2. Calculate the box's space diagonal.
  3. If the diagonal is longer than the item, it fits (assuming the item is thin enough to angle through).

A 22-inch sword in an 18 × 12 × 8 box?

Diagonal = √(324 + 144 + 64) = √532 ≈ 23.1 inches

Yes — 22 fits in 23.1.

Doorways: a different kind of diagonal problem

For getting furniture through a doorway, the diagonal you care about is the face diagonal:

Face diagonal = √(width² + depth²)

Compared to the doorway's diagonal:

Doorway diagonal = √(doorway width² + doorway height²)

If the appliance's face diagonal is less than the doorway's diagonal, you can tilt-walk it through. This is a 2D problem, not 3D.

Higher dimensions

The formula generalizes to any number of dimensions. For an n-dimensional rectangular "box" with sides s₁, s₂, ..., sₙ:

d = √(s₁² + s₂² + ... + sₙ²)

In one dimension, just the length of a line segment. In two, standard Pythagoras. In three, the box's space diagonal. In four (a "tesseract"), the formula still works.

Common mistakes

Adding instead of squaring

Using l + w + h instead of √(l² + w² + h²). For a 5 × 3 × 4 box, the sum is 12 — much larger than the actual diagonal of 7.07.

Forgetting the square root

Half-correct: l² + w² + h². For our box, that's 50. The diagonal is √50, not 50.

Mixing units

Convert all to the same unit first.

The diagonal of a cube

For a cube with side s:

d = √(3s²) = s × √3 ≈ 1.732 × s

For a 10 cm cube, the diagonal is 17.32 cm. √3 (Theodorus's constant) shows up in 3D geometry the way √2 shows up in 2D.

The takeaway

The space diagonal formula — d = √(l² + w² + h²) — is the 3D extension of Pythagoras's theorem. It tells you the longest straight line that fits inside a rectangular box. The math is straightforward: square each side, add them up, take the square root.