Law of Cosines Calculator
Written by Thierno Sadou Diallo, formula verified per our methodology • Last checked on 9/8/2026
The law of cosines gives c² = a² + b² − 2ab·cos(C), where C is the angle between sides a and b. For a=5, b=7, and an angle C of 60°, the third side c measures about 6.245 units.
Explanation
The law of cosines generalizes the Pythagorean theorem to any triangle, not just right triangles: it allows the length of one side to be calculated from the other two sides and the angle they form between them. When this angle equals exactly 90°, the term −2ab·cos(C) vanishes (since cos(90°) = 0), and the formula reduces exactly to the classic Pythagorean theorem, c² = a² + b² — a property directly checkable and checked on this calculator (see the second test case). For an angle other than 90°, this extra term corrects the formula to account for the actual tilt between the two sides: an obtuse angle (greater than 90°) makes this term positive (since cosine becomes negative), which lengthens the third side compared with an equivalent right triangle; an acute angle (less than 90°) shortens it. This law is particularly useful in triangulation (measuring distances via a triangle's geometry, in surveying or navigation), in physics (composing non-perpendicular vectors), and more generally whenever a triangle has no known right angle. For the hypotenuse of a specifically right triangle, see our hypotenuse calculator (Pythagorean theorem), more direct in that particular case.
Example: a=5, b=7, angle C=60°
Inputs
Side a: 5. Side b: 7. Angle C (between a and b): 60°.
Calculation
c² = 5² + 7² − 2×5×7×cos(60°) = 25 + 49 − 70×0.5 = 74 − 35 = 39. c = √39 ≈ 6.245.
Result
This triangle's third side measures about 6.245 units.
Frequently asked questions
Why does this law give back exactly the Pythagorean theorem at 90°?
Because the cosine of 90° equals exactly 0, which entirely cancels the term −2ab·cos(C) in the formula. Only c² = a² + b² remains, exactly the Pythagorean theorem: the law of cosines isn't a different formula, then, but a generalization that contains the Pythagorean theorem as a special case, when the angle between the two known sides is a right angle.
What happens if the entered angle is very obtuse, close to 180°?
An angle close to 180° means sides a and b are nearly aligned in opposite directions: the triangle becomes very 'flattened', and the third side c approaches the sum a + b (the exact limiting case at 180°, where the triangle degenerates into a straight line). Conversely, an angle close to 0° flattens the triangle the other way, and c approaches the difference |a − b|.
Can this formula also calculate an angle from the three sides?
Yes, the law of cosines can be rearranged the other way (cos(C) = (a² + b² − c²) ÷ (2ab)) to find an angle from three already-known sides. This calculator only covers the direction 'two sides and the included angle give the third side', the most common use case for sizing a triangle.