How it’s calculated
The law of cosines links the three sides of any triangle with one of its angles. It extends Pythagoras' theorem: when the angle is 90°, cos 90° = 0 and the last term disappears.
SAS (two sides and the angle between them): the first formula gives the third side. SSS (three sides): the rearranged form gives each angle. This calculator finds the remaining angles with the law of cosines as well, because the inverse cosine returns angles up to 180° and so is never ambiguous.
Example (OpenStax Precalculus 2e, §8.2 Example 1, relabelled): b = 10, c = 12 and A = 30°. Then a² = 100 + 144 − 240 × cos 30° = 244 − 120√3 ≈ 36.1539, so a ≈ 6.013. With three sides a = 20, b = 25, c = 18 (Example 2): cos A = (625 + 324 − 400) ÷ 900 = 0.61, so A ≈ 52.4°.
Frequently asked questions
When do I use the law of cosines?
When you know three sides (SSS) or two sides and the angle between them (SAS). If you know an angle and the side opposite it, the law of sines is quicker.
How is the law of cosines related to Pythagoras?
If angle C is 90°, cos C = 0 and c² = a² + b² − 2ab cos C becomes c² = a² + b². The −2ab cos C term corrects for angles that are not right angles.
Why can’t I get two answers like with the law of sines?
cos⁻¹ gives exactly one angle between 0° and 180°, which covers every possible triangle angle, so there is no ambiguous case.
Why do some side lengths give an error?
Three lengths make a triangle only if each is shorter than the sum of the other two. For example 2, 3 and 6 cannot close up.
Embed this calculator
Add this free calculator to your own website. Copy the code below into your page’s HTML:
Need this calculator branded, changed or built around your own prices?See custom business solutions →
Sources
Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.
Added · Last updated · How we check our calculators
Spotted a mistake or missing option? Report a problem· Suggest a calculator