Free tool
Law of cosines calculator, with every step shown.
Type two sides and the angle between them to find the third side, or type three sides to find all three angles. You can also give two sides and an angle that is not between them and see the one or two triangles that fit, or two angles and a side to use the law of sines. Each answer shows the formula with your numbers in it, and the triangle is drawn to scale, with its area, perimeter, heights, medians, inradius and circumradius, and whether it is acute, right or obtuse.
What you know
This case uses the law of sines, because the law of cosines needs a side pair or all three sides.
Use any length unit, as long as every side uses the same one. In radians you can type pi/3.
Worked out in your browser. Nothing is sent anywhere.
Guide
How to use the law of cosines, with worked examples.
The law of cosines links the three sides of a triangle to one of its angles: c² = a² + b² − 2ab cos C. This law of cosines calculator uses it three ways. Give two sides and the angle between them and it finds the third side. Give all three sides and it finds all three angles. Give two sides and an angle that is not between them and it finds the third side, with zero, one or two triangles. Give two angles and a side and it uses the law of sines, since the law of cosines needs a side pair. Each answer shows the formula with your numbers put in, and a triangle is drawn to scale.
How to use the law of cosines calculator
- Choose Two sides and the angle between, Three sides, Two sides and another angle or Two angles and a side.
- Type the sides and the angle. Side a is opposite angle A, side b is opposite B and side c is opposite C.
- Pick Degrees or Radians, and how many Decimal places you want.
- Read the big card first. The cards below give every side and angle, the area, the perimeter, the three heights, the three medians, the inradius, the circumradius and whether the triangle is acute, right or obtuse. Open Steps for the working.
- Copy result copies a one line answer and Copy link copies a link that keeps your numbers.
The formula, in all three forms
c² = a² + b² − 2ab cos C. The same rule holds for each corner, so a² = b² + c² − 2bc cos A and b² = a² + c² − 2ac cos B. To find an angle from three sides, turn it round: cos C = (a² + b² − c²) ÷ (2ab). When C is 90°, cos C is 0 and the rule becomes the Pythagorean theorem, c² = a² + b². The last term is what corrects for an angle that is wider or narrower than a right angle.
Worked example: two sides and the angle between (SAS)
Take a = 5, b = 7 and C = 49°. Then c² = 25 + 49 − 2 × 5 × 7 × cos 49° = 74 − 70 × 0.656059 = 74 − 45.9241 = 28.0759, so c = 5.2987. The angles follow from the same law: cos A = (49 + 28.0759 − 25) ÷ (2 × 7 × 5.2987) = 0.70201, so A = 45.41°, and B = 180° − 49° − 45.41° = 85.59°. The area is ½ × 5 × 7 × sin 49° = 13.21.
Worked example: three sides (SSS)
Take a = 5, b = 7 and c = 9. The largest angle sits opposite the longest side: cos C = (25 + 49 − 81) ÷ (2 × 5 × 7) = −7 ÷ 70 = −0.1, so C = 95.74°. A negative cosine means an obtuse angle. Then cos A = (49 + 81 − 25) ÷ (2 × 7 × 9) = 0.8333, so A = 33.56°, and B = 180° − 33.56° − 95.74° = 50.70°. The area from Heron's formula is 17.41.
Two sides and an angle that is not between them (SSA)
With a = 6, b = 8 and A = 30°, the law of cosines for side a becomes a quadratic in c: c² − 2 × 8 × cos 30° × c + (64 − 36) = 0. Its answers are c = b cos A ± √(a² − b² sin² A) = 6.9282 ± 4.4721, which gives c = 11.4003 or c = 2.4561. Both are positive, so two different triangles fit. The first has B = 41.81° and C = 108.19°. The second has B = 138.19° and C = 11.81°. This is the ambiguous case. If a is shorter than b × sin A the root is of a negative number and no triangle fits.
Worked example: two angles and a side (ASA or AAS)
The law of cosines needs two sides, so when you know two angles and one side the page switches to the law of sines. Take A = 40°, B = 65° and a = 10. The third angle is C = 180° − 40° − 65° = 75°. The common ratio is a ÷ sin A = 10 ÷ 0.642788 = 15.5572, so b = 15.5572 × sin 65° = 14.0996 and c = 15.5572 × sin 75° = 15.0271. Choose which side you know, a, b or c, and the other two follow.
The extra numbers for the triangle
For a = 5, b = 7 and c = 9 the semi-perimeter is 10.5 and the area is 17.4123. The height on a side is 2 × area ÷ that side, so the three heights are 6.9649, 4.9749 and 3.8694. The inradius, the radius of the circle inside the triangle, is area ÷ semi-perimeter = 1.6583. The circumradius, the radius of the circle through all three corners, is abc ÷ (4 × area) = 4.5227. A median joins a corner to the middle of the opposite side, and the one to side a has length ½√(2b² + 2c² − a²) = 7.6649.
Checking a result
Three quick checks catch most mistakes. The angles must add to 180°. The longest side must sit opposite the largest angle. And each side must be shorter than the other two added together. The page shows the angle sum in the steps. If a hand answer differs in the third or fourth decimal place, it is almost always rounding in an earlier step.
When to use the law of cosines or the law of sines
Use the law of cosines when you know SAS or SSS, because the law of sines needs an angle and its opposite side as a pair. Use the law of sines when you know two angles and a side (ASA or AAS), and the Two angles and a side option does that for you. The triangle calculator picks the right rule for you.
| You know | First step | Then |
|---|---|---|
| SAS | c² = a² + b² − 2ab cos C | angles from the rearranged form |
| SSS | cos C = (a² + b² − c²) ÷ (2ab) | the other two angles the same way |
| SSA | solve the quadratic in c | 0, 1 or 2 triangles |
| ASA or AAS | third angle, then the law of sines | the two other sides |
Common problems
- The angle is not between the sides. For SAS the angle must sit between the two sides. If it does not, use the SSA option.
- Calculator in the wrong mode. A 49 typed as radians is not 49°. Check the Angle unit.
- No triangle. Three sides only make a triangle when each is shorter than the other two added together. The page tells you which side breaks the rule.
- Rounding. The steps use more digits than they show, so a hand check with rounded numbers can differ in the last place.
To work out a right triangle, see the sine, cosine and tangent calculator. For angle values on the circle, use the unit circle chart.
Questions
Good to know.
What is the law of cosines?
It is the rule c² = a² + b² − 2ab cos C. It links the three sides of any triangle to one angle, and it works for every triangle, not only right ones.
When do I use the law of cosines instead of the law of sines?
Use it when you know two sides and the angle between them, or all three sides. The law of sines needs a matching side and angle pair.
How do I find an angle with the law of cosines?
Turn the rule round: cos C = (a² + b² − c²) ÷ (2ab), then take arccos. For sides 5, 7 and 9, cos C is −0.1 and C is 95.74°.
Why is my cosine negative?
A negative cosine means the angle is more than 90°, an obtuse angle. In a triangle only one angle can be obtuse, and it is opposite the longest side.
What if the law of cosines gives two answers?
That only happens with two sides and an angle that is not between them (SSA). The quadratic in c can have two positive roots, so two different triangles fit.
How is it related to the Pythagorean theorem?
When the angle is 90°, cos 90° is 0, the last term vanishes and you are left with c² = a² + b².
Does the unit of length matter?
No. Use centimetres, feet or anything else, as long as every side uses the same unit. Angles come out the same either way.
Can I type radians?
Yes. Choose Radians in Angle unit and type a number or a small sum such as pi/3.
What if I know two angles and a side?
Use the Two angles and a side option. It finds the third angle, then the other two sides with the law of sines, because the law of cosines cannot start from that case.
How do I find the area of a triangle from three sides?
Use Heron's formula: with s = (a + b + c) ÷ 2, the area is √(s(s − a)(s − b)(s − c)). For sides 5, 7 and 9 it is 17.4123. The page shows it for every case.
What are the inradius and circumradius?
The inradius is the radius of the circle that fits inside the triangle, area ÷ semi-perimeter. The circumradius is the radius of the circle through all three corners, abc ÷ (4 × area).