In three dimensions the Pythagorean theorem becomes d2 = l2 + w2 + h2. The space diagonal of a box with length l, width w and height h is d = √l2 + w2 + h2. You get it by using the ordinary theorem twice: once across the floor of the box, then once up to the opposite top corner.
The space diagonal in two steps
A space diagonal is the straight line through the inside of a box from one corner to the corner farthest from it. You can't measure it with one flat right triangle, because it doesn't lie in any face. But it is the hypotenuse of a right triangle that stands upright inside the box, and the base of that triangle is the hypotenuse of a second right triangle lying on the floor.
- Across the floor. The length and width meet at a right angle in the corner of the floor, so the floor diagonal f satisfies f2 = l2 + w2. This is the ordinary Pythagorean theorem formula, the same calculation as the diagonal of a rectangle.
- Up to the far corner. The vertical edge h stands straight up from the floor, so it is perpendicular to every line in the floor that passes through its foot, including f. That makes f, h and d a right triangle with hypotenuse d: d2 = f2 + h2.
- Combine. Replace f2 with l2 + w2:
Key ideaThe space diagonal of a box is d = √l2 + w2 + h2. Square the three edges, add, and take one square root at the end.
TipYou never need the floor diagonal itself. Its square is all that goes into step 2, so skip the first square root and avoid rounding errors. In the shoebox example below, f = √1300 is an ugly decimal, but d comes out as a whole number.
Worked examples
Example 1: the box in the animation
A box is 12 by 9 by 8. Find the space diagonal.
d2= 122 + 92 + 82 = 144 + 81 + 64 = 289d= √289 = 17The space diagonal is 17. Going through the floor diagonal gives the same answer: √144 + 81 = 15, then √225 + 64 = 17.
Example 2: a tall, narrow box
A box measures 3 by 4 by 12.
d= √32 + 42 + 122 = √9 + 16 + 144 = √169 = 13d = 13. The floor is a 3-4-5 triangle (floor diagonal 5), and the upright triangle is a 5-12-13 triangle.
Example 3: a shoebox
A shoebox is 30 cm long, 20 cm wide and 12 cm high.
d= √302 + 202 + 122 = √900 + 400 + 144 = √1444 = 38The space diagonal is exactly 38 cm, even though the floor diagonal, √1300 ≈ 36.06 cm, is not a whole number.
Example 4: finding a missing edge
A box is 6 cm long and 2 cm wide, and its space diagonal is 7 cm. How tall is it?
62 + 22 + h2= 7236 + 4 + h2= 49h2= 9, h = 3The box is 3 cm tall. Work backward exactly as you would to find a missing leg: subtract the known squares from d2.
For any other numbers, the 3D Pythagorean theorem calculator shows both steps of the working.
The diagonal of a cube
A cube is a box with all edges equal to s, so the two steps give neat results. Across a face, s2 + s2 = 2s2, so the face diagonal is s√2. Then up to the far corner, 2s2 + s2 = 3s2, so the space diagonal is s√3.
The face diagonal cuts each face into two 45-45-90 triangles, which is where √2 comes from.
Example 5: a 10 cm cube
Face diagonal: 10√2 ≈ 14.14 cm. Space diagonal: 10√3 ≈ 17.32 cm (both rounded to the nearest hundredth).
Going backward, a cube whose space diagonal is 12 cm has edges of 12 over √3 = 4√3 ≈ 6.93 cm.
The space diagonal of a cube rises at an angle θ above the floor, where tanθ = s over s√2 = 1 over √2, so θ ≈ 35.26°. Finding angles like this needs trigonometry; see Pythagoras or trig for when to use which.
Will it fit? Real-world problems
The space diagonal is the longest straight line that fits inside a box. That makes it the answer to a whole family of packing questions. In each one we treat the object as a thin line, so the answer is an upper limit: a thick object needs some extra room.
Example 6: a rod in a box
What is the longest thin rod that fits in a box measuring 50 cm by 40 cm by 30 cm?
d= √502 + 402 + 302 = √2500 + 1600 + 900 = √5000= 50√2 ≈ 70.71About 70.71 cm. A 70 cm rod fits; a 72 cm rod does not. Lying flat on the bottom, the longest rod would be only √4100 ≈ 64.03 cm.
Example 7: a tripod in a suitcase
A suitcase measures 55 cm by 35 cm by 20 cm inside. Will a 67 cm folded tripod fit?
floor: √552 + 352 = √4250 ≈ 65.19space: √552 + 352 + 202 = √4650 ≈ 68.19Laid flat across the bottom it does not fit (65.19 cm is too short), but tilted from a bottom corner to the opposite top corner it does, with about 1 cm to spare. A 70 cm tripod would not fit at all.
Example 8: a pole in a storage room
A storage room is 4 m long, 3 m wide and 2.5 m high. Can it hold a 5 m pole?
floor: √42 + 32 = 5space: √16 + 9 + 6.25 = √31.25 ≈ 5.59The floor diagonal is exactly 5 m, so the pole would only just touch both corners lying down. Tilted toward the far top corner there is about 5.59 m of room.
More problems like these, with full solutions, are on the word problems page and the printable 3D Pythagorean theorem worksheet.
The 3D distance formula
The same idea measures the straight-line distance between two points in space, (x1, y1, z1) and (x2, y2, z2). Picture the box that has the two points at opposite corners, with its edges parallel to the axes. Its edges are the differences |x2 − x1|, |y2 − y1| and |z2 − z1|, and the distance is its space diagonal:
d = √(x2 − x1)2 + (y2 − y1)2 + (z2 − z1)2It is the flat distance formula with a third term. Squaring removes any minus signs, so the order of the points doesn't matter.
Example 9: two points in space
Find the distance from A(1, −2, 3) to B(7, 1, −3). The differences are 7 − 1 = 6, 1 − (−2) = 3 and −3 − 3 = −6.
d= √62 + 32 + (−6)2 = √36 + 9 + 36 = √81 = 9The points are 9 units apart.
Example 10: a drone flight
A drone takes off from (0, 0, 0) and flies in a straight line to a point 40 m east, 30 m north and 120 m up, (40, 30, 120).
d= √402 + 302 + 1202 = √1600 + 900 + 14,400 = √16,900 = 130It flies 130 m. (Divide everything by 10 and you get the 3-4-12-13 box from Example 2.)
All the points at distance r from the origin satisfy x2 + y2 + z2 = r2: a sphere. That is the 3D version of the equation of a circle.
Pyramids: slant height and edge length
A square pyramid hides two different right triangles, and mixing them up is a common mistake. Both stand on the height, which runs from the top straight down to the center of the base.
Example 11: a square pyramid
A square pyramid has base side 10 m and height 12 m. Find the slant height (to the middle of a base edge) and the length of a sloping edge (to a corner).
Slant height. The center of the base is half a side, 5 m, from the middle of an edge:
ℓ = √122 + 52 = √169 = 13Edge. A corner is half a diagonal from the center. The base diagonal is 10√2, so half of it is 5√2, and its square is 50. This is step 1 of the two-step method:
e = √122 + (5√2)2 = √144 + 50 = √194 ≈ 13.93Slant height 13 m; edge √194 ≈ 13.93 m. The edge is always the longer of the two, because a corner is farther from the center than the middle of an edge.
Slant heights of cones, and the flat version of this problem, are covered on the height of a triangle page.
Going further
Boxes whose edges and space diagonal are all whole numbers are called Pythagorean quadruples: 1-2-2-3, 2-3-6-7, 1-4-8-9, 2-6-9-11, 3-4-12-13 and 8-9-12-17 (the box in the animation) are examples. The two-step argument keeps working in any number of dimensions, adding one square per dimension, as shown on the Pythagorean theorem in n dimensions page. There is even a 3D version of the theorem for areas instead of lengths: de Gua's theorem.
Frequently asked questions
What is the 3D Pythagorean theorem formula?
For a box with edges l, w and h, the space diagonal d satisfies d2 = l2 + w2 + h2. In coordinates, the distance between two points is √Δx2 + Δy2 + Δz2.
What is a space diagonal?
It is a line segment joining two corners of a solid that do not lie on the same face, so it passes through the inside. In a rectangular box it runs from a corner to the opposite corner, and it is the longest straight line that fits in the box.
How do you find the diagonal of a cube?
Multiply the edge by √3. A cube with edges of 5 cm has a space diagonal of 5√3 ≈ 8.66 cm. The diagonal of one face is the edge times √2.
What is the difference between a face diagonal and a space diagonal?
A face diagonal crosses one flat face of the box and uses two edges: √l2 + w2. A space diagonal crosses the inside of the box and uses all three: √l2 + w2 + h2. The space diagonal is always longer.
How many diagonals does a box have?
A rectangular box has 4 space diagonals, all the same length, joining each corner to the opposite one. It also has 12 face diagonals, two on each of its six faces.
Does it matter which edge I call the length, width or height?
No. Addition doesn't depend on order, so l2 + w2 + h2 is the same whichever way round you label the edges. You can do the "floor" step with any two of them.
Keep exploring
- Calculators3D Pythagorean Theorem CalculatorFind the space diagonal of a box from its length, width and height, or a missing side from the diagonal, with steps, exact answers and face diagonals.
- TriplesPythagorean QuadruplesPythagorean quadruples are whole-number boxes with a whole-number space diagonal: full list up to d = 41, how to make them, Euler bricks and the perfect cuboid.
- LearnThe Distance FormulaThe distance formula explained: derive it from the Pythagorean theorem, use it with negative coordinates, avoid sign mistakes and extend it to 3D.
- Practice3D Pythagorean Theorem WorksheetPrintable 3D Pythagorean theorem worksheet: 12 problems on boxes, cubes, cones and square pyramids, each with a 3D drawing, plus a fully worked answer key.
- LearnThe Pythagorean Theorem in n DimensionsThe Pythagorean theorem in n dimensions: the Euclidean norm, orthogonal vectors and the dot product, inner-product spaces, Parseval's identity and data science.