The law of cosines is the Pythagorean theorem extended to every triangle. Give it two sides and the angle between them and it returns the third side; give it three sides and it returns every angle. This calculator also solves two sides with a non-included angle, as a quadratic.
How to use the law of cosines calculator
- In What do you want to find?, choose the third side from two sides and the angle between them (SAS), all three angles from three sides (SSS), or the third side from two sides and an angle not between them (SSA).
- Enter Side a and Side b, then Angle C (between a and b) for SAS, Side c for SSS, or Angle A (opposite side a) for SSA.
- Choose the Units (feet by default) and the Angle unit, degrees or radians.
- The headline is the third side c (SAS and SSA) or the three angles (SSS). The tape adds every side and angle, the perimeter, area and triangle type, plus a table of heights, medians and radii. If SSA has two answers, both triangles appear side by side.
Law of cosines formulas
For SSA, with angle A opposite side a:
How it generalizes the Pythagorean theorem
When C = 90°, cos C = 0 and the formula collapses to c² = a² + b²: sides 3 and 4 at a right angle give c = 5. The term −2ab cos C corrects for a corner that isn’t square. Below 90° that term is negative, so the third side is shorter than the Pythagorean value; above 90° it is positive and the side is longer. Euclid stated the result geometrically in Book II, Propositions 12 and 13, of the Elements.
Worked example: distance between two ships
From a lighthouse, ship P is 9 km away on a bearing of 035° and ship Q is 14 km away on a bearing of 110°, so the sight lines are 110° − 35° = 75° apart. Choose SAS and enter Side a = 9, Side b = 14 and Angle C = 75, in km.
- c² = 9² + 14² − 2 × 9 × 14 × cos 75° ≈ 277 − 65.22 = 211.78
- Distance between the ships: c = √211.78 ≈ 14.55 km
- Remaining angles: about 36.68° at Q, opposite the 9 km side, and 68.32° at P.
The same setup gives a hiker’s distance from the start: 3 mi, then 2 mi with a 110° angle between the legs, leaves you about 4.14 mi away.
Law of cosines or law of sines?
| You know | Start with | Why |
|---|---|---|
| SAS | Law of cosines | No side is paired with its opposite angle |
| SSS | Law of cosines | Only sides are known |
| AAS or ASA | Law of sines | The angle sum completes a matched pair |
| SSA | Either | Both reveal 0, 1 or 2 triangles |
Tip: find the largest angle first
If you solve SSS by hand and switch to the law of sines after one angle, find the largest angle (opposite the longest side) with the law of cosines first. An inverse cosine returns any angle from 0° to 180°; an inverse sine only returns up to 90°. With sides 7, 9 and 14 ft, cos C = (49 + 81 − 196) ÷ 126 ≈ −0.5238, so C ≈ 121.59°. Had you found A ≈ 25.21° first and used the law of sines for C, you would get sin C ≈ 0.8518 and an inverse sine of 58.41°, the supplement of the true answer. Once the largest angle is known, the other two must be acute, so either law is safe. The calculator uses inverse cosines and the angle sum, so it avoids this trap.
For very thin triangles, a² + b² − 2ab cos C subtracts nearly equal numbers and magnifies rounding error; the equivalent c² = (a − b)² + 4ab sin²(C ÷ 2) avoids that.
The SSA case as a quadratic
The SSA default, a = 8 ft, b = 11 ft and A = 40°, gives c² − 16.853c + 57 = 0. The discriminant is about 56.02, so c = (16.853 ± 7.485) ÷ 2: either 12.17 ft or 4.68 ft. Both roots are positive, so two triangles fit, with B ≈ 62.11° or 117.89°. When a is longer than b, the constant b² − a² is negative, the roots have opposite signs and only one triangle exists. A negative discriminant means side a is too short to close the triangle.
See also the law of sines calculator and, for right triangles, the Pythagorean theorem calculator.
Frequently asked questions
What is the law of cosines?
For any triangle, c² = a² + b² − 2ab cos C, where C is the angle between sides a and b. It works for acute, right and obtuse triangles, and it becomes the Pythagorean theorem when C is 90°.
How do I find an angle from three sides?
Rearrange the formula to cos C = (a² + b² − c²) ÷ 2ab, then take the inverse cosine. With sides 7, 9 and 14, cos C ≈ −0.5238, so the angle opposite the 14 side is about 121.59°.
When should I use the law of cosines instead of the law of sines?
Use it when you know two sides and the angle between them (SAS) or all three sides (SSS). The law of sines needs a side paired with its opposite angle, and neither of those cases gives you one.
Can the law of cosines solve the SSA case?
Yes. Writing the formula around the known angle A gives a quadratic in the unknown side: c² − (2b cos A)c + (b² − a²) = 0. Two positive roots mean two triangles, one positive root means one, and no real root means none.
What if my three sides cannot form a triangle?
The two shorter sides must add up to more than the longest one. If they don't, the calculator says so, showing the shorter sides' total next to the longest side, instead of returning angles.