Geometry
How To Calculate The Diagonal Of A Rectangular Prism
The diagonal of a rectangular prism is the longest straight line you can draw inside it, running between opposite corners through the solid. This page shows how the three edge lengths combine under a three-dimensional version of Pythagoras' theorem, how that space diagonal differs from the face diagonals, and how to compute the volume at the same time.
Last updated
Quick Answer
d = sqrt(l^2 + w^2 + h^2)
- l
- Length of the prism
- w
- Width of the prism
- h
- Height of the prism
- d
- Space diagonal from corner to opposite corner
Square the length, width and height, add the three squares, then take the square root to get the space diagonal. A face diagonal uses only two of the edges: the base diagonal is sqrt(l^2 + w^2) and the side diagonal is sqrt(w^2 + h^2). For a prism measuring 3 by 4 by 12 units, the space diagonal is 13, the base diagonal is 5, the side diagonal is 12.649110640673518 and the volume is 144 cubic units.
What Is The Diagonal Of A Rectangular Prism?
A rectangular prism, often called a cuboid, is a solid bounded by six rectangular faces that meet at right angles. Its space diagonal is the straight segment joining one corner to the corner diagonally opposite it, passing through the interior of the solid rather than across any one face. Because it cuts through the body of the shape, it is sometimes called the body diagonal to distinguish it from the diagonals drawn on the flat faces. There are four such space diagonals in a cuboid, and symmetry makes them all the same length. The space diagonal is a length, so it is measured in ordinary linear units such as millimetres, metres or inches.
The formula comes directly from Pythagoras' theorem, the rule that the square on the hypotenuse of a right-angled triangle equals the sum of the squares on the other two sides. In two dimensions a rectangle of sides l and w has a diagonal whose square is l squared plus w squared. To move into three dimensions, apply the same rule again: the base diagonal already has length sqrt(l squared plus w squared), and the height h stands at right angles to that base diagonal. Treating the base diagonal and the height as the two perpendicular legs of a new right-angled triangle gives a hypotenuse whose square is l squared plus w squared plus h squared. The space diagonal is therefore the square root of the sum of all three squared edges, a result known as the three-dimensional Pythagorean theorem.
A face diagonal lies entirely on one of the six rectangular faces and uses only two edges. The base diagonal spans the floor of the prism, so it depends on length and width alone and ignores the height completely. In the worked prism with length 3, width 4 and height 12, the base diagonal is sqrt(9 plus 16), which is sqrt(25), or exactly 5. Changing the height has no effect whatsoever on this particular diagonal, which is why it is worth computing separately when a problem asks about the floor or the lid of a box rather than the whole solid.
The side diagonal spans a side face and, in the convention used here, is built from the width and the height while ignoring the length. For the same prism it is sqrt(16 plus 144), that is sqrt(160), which evaluates to 12.649110640673518. Notice that this is only a little larger than the height of 12, because the width of 4 contributes a modest amount under the square root. A cuboid has two distinct types of side face, one formed by width and height and the other by length and height, so label the edges before substituting whenever length and width differ.
The space diagonal is always longer than any face diagonal, and this follows from the formula rather than a separate check. Adding a positive squared edge under the square root can only increase the result, so the space diagonal exceeds the base diagonal and the side diagonal. In the worked case 13 is greater than both 5 and 12.649110640673518. A pleasing pattern appears here: the base diagonal of 5 and the height of 12 themselves form a five-twelve-thirteen Pythagorean triple, so the space diagonal of 13 follows from a second application of the theorem.
The volume of the prism is a different quantity again and must not be confused with any diagonal. Volume is length times width times height, giving 3 multiplied by 4 multiplied by 12, or 144 cubic units in the worked case. A diagonal is a length measured in metres, whereas volume is measured in cubic metres, so the two can never be interchanged. The calculator reports both because design and packing problems often need them together: the diagonal gives the longest rod that fits inside a box, while the volume gives how much it can hold.
Several practical questions reduce to this calculation. A removal company deciding whether a long pole fits inside a van needs the space diagonal, not the length of the floor. Someone choosing a screen or display case often wants the corner-to-corner measurement across a face instead. In three-dimensional graphics the distance between two points whose coordinate differences are the three edge lengths uses exactly the same square-and-root routine. Because the space diagonal formula is symmetric in length, width and height, permuting the dimensions leaves it unchanged; face diagonals depend on which pair you select.
The formula assumes a true rectangular prism with flat faces meeting at right angles. If a box is sheared into a slanted parallelepiped, adjacent edges are no longer perpendicular and the sum of squares is wrong; a rule involving angles is then required. Within its assumptions the method is exact, and a cube is simply the special case in which all three edges are equal. For a cube of side 2, each squared edge is 4, the sum is 12 and the space diagonal is about 3.4641016151377544, while each face diagonal is about 2.8284271247461903.
A useful mental check comes from considering extreme shapes. Take a long, thin prism measuring 1 by 2 by 10 units: the squared edges are 1, 4 and 100, so the sum is 105 and the space diagonal is about 10.246950765959598, only slightly longer than the dominant edge of 10. Doubling one edge does not double the diagonal, because the square root compresses the change: doubling the height of the worked prism from 12 to 24 raises the space diagonal only from 13 to about 24.515301344262525, not to 26. Keeping this nonlinearity in mind helps you spot implausible answers when sizing packaging or checking a diagonal brace.
Formula
d = sqrt(l^2 + w^2 + h^2)
Formula page →Square each of the three perpendicular edges, add the squares and take the square root. This is Pythagoras' theorem applied twice, once across the base and once from the base diagonal up to the opposite corner.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| l | Length | length | One horizontal edge of the prism, measured along the base. |
| w | Width | length | The other horizontal edge of the prism, at right angles to the length. |
| h | Height | length | The vertical edge, perpendicular to both length and width. |
d_base = sqrt(l^2 + w^2), d_side = sqrt(w^2 + h^2)
Formula page →A face diagonal uses only the two edges that bound that face. The base diagonal ignores height; the side diagonal described here ignores length. Always check which pair of edges the face in question actually uses.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| l | Length | length | Appears in the base diagonal together with the width. |
| w | Width | length | Shared by the base diagonal and the side diagonal. |
| h | Height | length | Appears in the side diagonal together with the width. |
V = l * w * h
Formula page →Volume is the product of the three edge lengths and is measured in cubic units. It is reported alongside the diagonals because the two quantities are often needed for the same design problem, but they are not interchangeable.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| l | Length | length | First factor of the volume product. |
| w | Width | length | Second factor of the volume product. |
| h | Height | length | Third factor of the volume product. |
How To Calculate The Diagonal Of A Rectangular Prism
- 1
Identify the three perpendicular edges
Write down the length, width and height of the prism and confirm that they meet at right angles. In the worked prism the edges are 3, 4 and 12, so length is 3, width is 4 and height is 12; the side diagonal is then formed by width and height.
- 2
Square each edge
Multiply each edge by itself: 3 times 3 is 9, 4 times 4 is 16 and 12 times 12 is 144. Squaring removes any concern about sign and turns each edge into the area of a square built on it, which is exactly the quantity Pythagoras' theorem adds together. Keep these three squares written down, because different diagonals use different subsets of them.
- 3
Add the appropriate squares
For the space diagonal add all three squares: 9 plus 16 plus 144 gives 169. For the base diagonal add only length and width squares: 9 plus 16 gives 25. For the side diagonal add only width and height squares: 16 plus 144 gives 160. Selecting the right subset at this stage is the single most important decision in the whole calculation, so check which corners the line you want actually joins.
- 4
Take the square root
The diagonal is the square root of each sum. The square root of 169 is exactly 13, the square root of 25 is exactly 5, and the square root of 160 is 12.649110640673518. Preserve the full value of any non-integer root during calculation and round only at the end for presentation, since early rounding introduces avoidable error into any figure derived from the diagonal.
- 5
Compute the volume and check consistency
Multiply the three edges for the volume: 3 times 4 times 12 is 144 cubic units. Then check that the space diagonal of 13 exceeds both the base diagonal of 5 and the side diagonal of 12.649110640673518, as it must. If a supposed space diagonal comes out shorter than a face diagonal, you have used the wrong subset of squares and should return to the previous step.
Examples
Example 1: The reference prism — 3 by 4 by 12 units
- length
- 3
- width
- 4
- height
- 12
| Step | Calculation | Result |
|---|---|---|
| Square the length | 3 x 3 | 9 |
| Square the width | 4 x 4 | 16 |
| Square the height | 12 x 12 | 144 |
| Add all three squares | 9 + 16 + 144 | 169 |
| Take the square root | sqrt(169) | 13 |
Result: The space diagonal is 13 units. The base diagonal is 5, the side diagonal is 12.649110640673518 and the volume is 144 cubic units.
Example 2: A cube of side 2 units
- length
- 2
- width
- 2
- height
- 2
| Step | Calculation | Result |
|---|---|---|
| Square the length | 2 x 2 | 4 |
| Square the width | 2 x 2 | 4 |
| Square the height | 2 x 2 | 4 |
| Add all three squares | 4 + 4 + 4 | 12 |
| Take the square root | sqrt(12) | 3.4641016151377544 |
Result: The space diagonal of the cube is about 3.4641016151377544 units, each face diagonal is about 2.8284271247461903 and the volume is 8 cubic units.
Example 3: A long thin prism — 1 by 2 by 10 units
- length
- 1
- width
- 2
- height
- 10
| Step | Calculation | Result |
|---|---|---|
| Square the length | 1 x 1 | 1 |
| Square the width | 2 x 2 | 4 |
| Square the height | 10 x 10 | 100 |
| Add all three squares | 1 + 4 + 100 | 105 |
| Take the square root | sqrt(105) | 10.246950765959598 |
Result: The longest rod that fits is the space diagonal, about 10.246950765959598 units. The base diagonal is about 2.23606797749979 and the volume is 20 cubic units.
Calculator
Space diagonal
13
- Base diagonal
- 5
- Side diagonal
- 12.6491
- Volume
- 144
Values update as you type. This calculator covers the single scenario its formula assumes — see Common Mistakes for what it leaves out.
Prefer a full-width tool? Open the The Diagonal Of A Rectangular Prism calculator page.
Common Mistakes
Adding the edges instead of their squares
Pythagoras' theorem adds squared lengths, not the raw edges. Adding 3, 4 and 12 gives 19, which is not a diagonal of anything. Always square each edge first, then add, then take the square root.
Forgetting the final square root
The sum of squares, 169 in the worked case, is not the diagonal; it is the square of the diagonal. Stopping there reports a value far larger than any edge and is easy to catch with a sanity check against the prism's dimensions.
Confusing a face diagonal with the space diagonal
A face diagonal lies on one flat face and uses only two edges, whereas the space diagonal passes through the interior and uses all three. Reporting 5 for the worked prism answers a question about the base only, not about the whole solid.
Choosing the wrong pair of edges for a side diagonal
The side diagonal used here is formed from width and height, giving sqrt(16 plus 144). Using length and height instead gives sqrt(9 plus 144), a different number. Label the face you are measuring before you substitute, particularly when length and width are unequal.
Reporting the diagonal in square units
A diagonal is a length, so it carries linear units such as metres or inches, never square or cubic units. If an answer is printed in square metres, the square root was probably omitted or the volume was confused with the diagonal.
Assuming that doubling an edge doubles the diagonal
Because of the square root, the diagonal grows more slowly than the largest edge. Doubling the height of the worked prism from 12 to 24 raises the space diagonal only from 13 to about 24.515301344262525, not to 26. Expect this compressed response whenever one edge dominates.
Applying the formula to a sheared solid
The square-and-sum rule requires edges that meet at right angles. A slanted parallelepiped or an irregular box has oblique angles, so its diagonals need a formula that includes those angles. Confirm the shape is truly rectangular before using this method.
FAQ
What is the difference between a face diagonal and a space diagonal?
A face diagonal is drawn across one rectangular face and uses just two edges, such as length and width for the base. A space diagonal joins opposite corners through the interior and uses all three edges. The space diagonal is always the longer of the two, because it includes one more squared edge under the square root.
Does it matter which edge I call length, width or height?
For the space diagonal it makes no difference at all, because the formula adds all three squares symmetrically. For a face diagonal it matters a great deal, since you must use the two edges that bound that particular face. Keep the labels consistent throughout a problem.
Why is the space diagonal longer than every face diagonal?
Each face diagonal is the square root of a sum of two squared edges, while the space diagonal is the square root of the sum of all three. Adding a further positive square can only increase the total, so the space diagonal must exceed each face diagonal whenever all three edges are nonzero.
Can I use the same calculation for a cube?
Yes. A cube is a rectangular prism with all three edges equal, so the space diagonal becomes the edge length times the square root of three. For an edge of 2 the space diagonal is about 3.4641016151377544, and each face diagonal is the edge length times the square root of two.
What units should the answer have?
The diagonal is a length, so use the same linear unit you used for the edges: centimetres, metres, inches and so on. Do not report it in square units. The volume, by contrast, is measured in cubic units and is a different quantity entirely.
How does this help me work out the longest object that fits in a box?
The longest straight object that can lie inside a rectangular box has the length of the space diagonal, provided its thickness is negligible. Compute the square root of the sum of the three squared internal dimensions, and remember to use the internal rather than external measurements of the container.
References
- [1]Wikipedia, Cuboid — https://en.wikipedia.org/wiki/Cuboid
- [2]Wikipedia, Pythagorean theorem — https://en.wikipedia.org/wiki/Pythagorean_theorem
- [3]Wikipedia, Diagonal — https://en.wikipedia.org/wiki/Diagonal
