Diagonal Calculator

This calculator finds the diagonal of a rectangle or square using the Pythagorean theorem, and extends the concept to the space diagonal of a 3D box. For a rectangle with width and height, the diagonal is sqrt(width² + height²). For a square with side s, the diagonal is s * sqrt(2). For a 3D rectangular box with length, width, and height, the space diagonal (the longest line connecting two opposite corners through the interior) is sqrt(length² + width² + height²). Enter your dimensions and the calculator displays the diagonal length instantly. Common applications include screen sizes (measured diagonally), picture frame dimensions, bookshelf layouts, room diagonal measurements, and packaging design.

Choose shape type
Width or first dimension
Height or second dimension
Diagonal--

Diagonal formulas

Rectangle: diagonal = sqrt(width² + height²)
Square: diagonal = side * sqrt(2)
3D Box: diagonal = sqrt(length² + width² + height²)

Polygon diagonal count formula

Number of diagonals = n(n - 3) / 2
where n = number of sides

Examples:

  • Triangle (3 sides): 3(0)/2 = 0 diagonals
  • Square (4 sides): 4(1)/2 = 2 diagonals
  • Pentagon (5 sides): 5(2)/2 = 5 diagonals
  • Hexagon (6 sides): 6(3)/2 = 9 diagonals

Diagonal calculator: frequently asked questions

How do I find the diagonal of a rectangle?

Use the Pythagorean theorem: diagonal = sqrt(width² + height²). For example, a rectangle 3 units wide and 4 units high has a diagonal of sqrt(3² + 4²) = sqrt(9 + 16) = sqrt(25) = 5 units. The diagonal is the longest straight line you can draw inside the rectangle, connecting two opposite corners.

How do I find the diagonal of a square?

For a square with side length s, the diagonal is s * sqrt(2). For example, a square with side 5 units has a diagonal of 5 * sqrt(2) ≈ 7.07 units. This is a special case of the rectangle formula where width and height are equal.

What is the diagonal of a 3D box?

A 3D box (rectangular prism) has a space diagonal connecting two opposite corners through the interior. The formula is: diagonal = sqrt(length² + width² + height²). For example, a box that is 3 by 4 by 5 units has a space diagonal of sqrt(9 + 16 + 25) = sqrt(50) ≈ 7.07 units.

How many diagonals does a polygon have?

A polygon with n sides has n(n-3)/2 diagonals. A triangle (3 sides) has 3(0)/2 = 0 diagonals. A square (4 sides) has 4(1)/2 = 2 diagonals. A pentagon (5 sides) has 5(2)/2 = 5 diagonals. A hexagon (6 sides) has 6(3)/2 = 9 diagonals.

Why is the Pythagorean theorem used for diagonals?

The diagonal of a rectangle forms the hypotenuse of a right triangle, where the width and height are the two legs. The Pythagorean theorem states that the hypotenuse² = leg1² + leg2². This principle extends to 3D boxes, where the space diagonal relates to three perpendicular dimensions.

Official sources

Reviewed by the CalculatorHub team, edited by James Graham, 14 June 2026. See our methodology.