Law of cosines calculator
Enter three known values of a triangle and solve for the missing side or angle.
How to use this calculator
Give any three of the four values (sides a, b, c and the angle C between a and b). Leave the unknown blank and the calculator solves it with every step shown.
How it works
For a missing side: c² = a² + b² − 2ab·cos(C). For a missing angle: cos(C) = (a² + b² − c²) ÷ 2ab, then C = arccos of that value, converted to degrees.
Worked example
a = 5, b = 7, C = 60°: c² = 25 + 49 − 2·5·7·cos60° = 74 − 35 = 39, so c = √39 ≈ 6.245.
Common mistakes
- Using the law of cosines when you actually have a right triangle, Pythagoras is simpler.
- Angle mode: the formula needs the angle in degrees here.
When to use it
Any non-right triangle where you know two sides and the included angle (SAS), or all three sides (SSS).
Frequently asked questions
Cosines for SAS and SSS cases; sines for ASA, AAS and SSA cases.
Yes, the formula handles any angle from 0° to 180°.
Finding an angle when all three sides are known
The side form of the law solves for a missing side. Rearranged, the same relationship solves for a missing angle, which is the version you need in the SSS case. Isolate the cosine term, compute the fraction, and then apply arccos to turn that fraction back into an angle in degrees.
Two checks keep this reliable. First, the fraction must sit between -1 and 1, since no cosine can leave that range; a value outside it means the three sides cannot form a triangle. Second, read the sign: a positive cosine gives an acute angle, zero gives a right angle, and a negative cosine gives an obtuse angle, with side c longest in that last case.
Example: Find angle C when a = 8, b = 6, and c = 7
Step 1, Substitute: cos(C) = (8^2 + 6^2 – 7^2) / (2*8*6) = (64 + 36 – 49) / 96 = 51 / 96.
Step 2, Simplify: 51 / 96 = 0.53125. The value is inside the valid range and positive, so angle C will be acute.
Step 3, Apply arccos: C = arccos(0.53125), which is about 57.91 degrees.
Putting the law to work
This angle form is the workhorse behind distance and direction problems that never contain a right angle: the bearing between two points reached by two straight legs, the corner angle of a plot of land from three measured boundary lengths, or the angle between two forces acting at a point. In each case you measure or derive the three sides first, let the formula return the angle, and then sanity check the result against the side lengths, since the largest angle always sits opposite the longest side. In the example above, side a is longest, so angle A must be larger than the 57.91 degrees found for angle C.
More questions
Yes. Rearrange the formula as cos(C) = (a^2 + b^2 – c^2) / (2ab) and take arccos. With sides 5, 7, and 9, the angle opposite the side of length 9 has cos(C) = (25 + 49 – 81) / 70 = -0.1, so C is about 95.74 degrees.
Yes. When C is a right angle, cos(C) = 0, the correction term -2ab cos(C) vanishes, and c^2 = a^2 + b^2 remains. The extra term adjusts the result for angles that are sharper or wider than 90 degrees.