Law of Cosines Calculator

The law of cosines is a fundamental theorem in trigonometry that relates the sides and angles of any triangle. Unlike the Pythagorean theorem, which applies only to right triangles, the law of cosines works for all triangles, whether acute, obtuse, or right-angled. The formula is c² = a² + b² - 2ab·cos(C), where a and b are two sides, C is the angle between them, and c is the opposite side. Use this calculator in two main modes: (1) given two sides and the included angle (SAS), solve for the third side and remaining angles; (2) given all three sides (SSS), solve for all three angles. The calculator shows the formula, the step-by-step calculation, and all results with clear labels. A worked example is included below. This tool is useful for surveyors, engineers, architects, and anyone solving triangle problems in physics, navigation, or construction.

Choose calculation mode
First side
Second side
Angle between sides a and b
Side c--
Angle A (degrees)--
Angle B (degrees)--
Angle C (degrees)--
Triangle perimeter--

Law of cosines formulas

c² = a² + b² - 2ab·cos(C)
cos(A) = (b² + c² - a²) / (2bc)
cos(B) = (a² + c² - b²) / (2ac)
cos(C) = (a² + b² - c²) / (2ab)

Worked example (SAS mode)

Given: side a = 5, side b = 7, angle C = 60 degrees. Find side c and other angles.

  1. c² = 5² + 7² - 2(5)(7)cos(60°) = 25 + 49 - 70(0.5) = 74 - 35 = 39
  2. c = sqrt(39) = 6.24
  3. cos(A) = (7² + 6.24² - 5²) / (2·7·6.24) = (49 + 38.94 - 25) / 87.36 = 62.94 / 87.36 = 0.7206
  4. A = arccos(0.7206) = 43.9 degrees
  5. Sum of angles: A + B + C = 180, so B = 180 - 43.9 - 60 = 76.1 degrees

Law of cosines calculator: frequently asked questions

What is the law of cosines?

The law of cosines relates the sides and angles of any triangle. If a, b, c are the sides and C is the angle opposite side c, then c² = a² + b² - 2ab·cos(C). It generalizes the Pythagorean theorem: when C = 90 degrees, cos(C) = 0, so c² = a² + b², which is the Pythagorean theorem.

When do I use the law of cosines?

Use the law of cosines when you know either: (1) two sides and the included angle (SAS), to find the third side; (2) all three sides (SSS), to find any angle; or (3) two sides and a non-included angle (SSA), to find another angle or side. It works for any triangle, not just right triangles.

What is the difference between SSS, SAS, and SSA?

SSS (side-side-side) means you know all three sides and want to find angles. SAS (side-angle-side) means you know two sides and the angle between them. SSA (side-side-angle) means you know two sides and an angle that is not between them (the non-included angle).

Can I use the law of cosines to find angles?

Yes. If you know all three sides (SSS), you can rearrange the law of cosines to solve for the cosine of any angle: cos(C) = (a² + b² - c²) / (2ab). Then use the inverse cosine (arccos) to find the angle. This calculator does this automatically.

Why is the law of cosines called the extended Pythagorean theorem?

Because it works for all triangles, not just right triangles. When the angle is 90 degrees, cos(90) = 0, so the formula reduces to the Pythagorean theorem c² = a² + b². For obtuse or acute angles, the law of cosines accounts for the extra or missing area.

Official sources

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