Law of Cosines Calculator
Solve any triangle with the Law of Cosines c² = a² + b² − 2ab·cos(C).
Enter sides and angles to find unknown measurements, area, and perimeter.
The Law of Cosines is a fundamental formula in trigonometry that relates the lengths of the sides of a triangle to the cosine of one of its angles. It is a generalization of the Pythagorean theorem, which only works for right triangles.
The formula:
c² = a² + b² − 2ab × cos(C)
Where:
- a and b are two known sides of the triangle
- C is the angle between sides a and b (the included angle)
- c is the side opposite to angle C
When to use the Law of Cosines:
You use this formula in two main situations. First, when you know two sides and the included angle (SAS) and want to find the third side. Second, when you know all three sides (SSS) and want to find any angle.
Solving for an angle (SSS case):
Rearranging the formula gives: C = arccos((a² + b² − c²) / (2ab))
Practical examples:
Surveyors use the Law of Cosines to calculate distances that cannot be measured directly. For instance, if you can measure two distances from a reference point to two landmarks and the angle between them, you can calculate the distance between the landmarks. Navigation, engineering, and architecture all rely on this formula regularly.
Relationship to the Pythagorean theorem: When angle C is exactly 90 degrees, cos(90°) = 0, so the formula simplifies to c² = a² + b², which is the familiar Pythagorean theorem. This makes the Law of Cosines a more general and powerful tool.
Equivalent forms. The formula can be written symmetrically for each side. Pick whichever one puts your unknown on the left:
- a² = b² + c² − 2bc · cos(A), when side a is unknown
- b² = a² + c² − 2ac · cos(B), when side b is unknown
- c² = a² + b² − 2ab · cos(C), when side c is unknown
For finding an angle when all three sides are known, rearrange to: cos(A) = (b² + c² − a²) / (2bc), and similarly for B and C.
Tips:
- Angles must be in degrees for this calculator (0° to 180°).
- The sum of all angles in any triangle is always exactly 180°.
- If a calculated angle comes out negative or greater than 180°, the triangle is invalid.
- To find the area after solving, use: Area = ½ × a × b × sin(C).
A note on origin. A geometric version of this law appears in Euclid’s Elements (Book 2, Propositions 12 and 13) around 300 BC, though Euclid stated it as a relationship between rectangles and squares rather than in modern trigonometric form. The cosine notation only became standard in the 16th and 17th centuries; the algebraic form we use today was settled in 19th-century European textbooks. Two-thousand-year-old mathematics, slightly rewritten.
Why SAS and SSS, and not the others. The Law of Cosines is the right tool when you have either two sides and the included angle (SAS), or all three sides (SSS). For ASA and AAS triangles, the Law of Sines is faster. For SSA (the ambiguous case) you can use either, but Law of Cosines side-steps the ambiguity by solving for an angle directly from a quadratic, which can give two valid solutions cleanly rather than as a separate check.
How we build and check this calculator
This calculator runs entirely in your browser, so the numbers you enter stay on your device. The math behind it is written by hand and tested against worked examples and standard references before the page goes live.
SuperGlobalCalculator is independently built and maintained. See how we build and verify our calculators.