Formula for calculating the diagonal of a square and the diagonal of a rectangle To calculate the diagonal of a square or rectangle, you just need to apply the Pythagorean theorem to a right triangle.