Pick the unit your lengths are in. Areas are then labelled in square units and volumes in cubic units; nothing is converted.
What the law of cosines says
In any triangle,
c² = a² + b² − 2ab · cos C
where C is the angle between sides a and b, and c is the side opposite that angle.
Look at the right-hand side again. The first two terms are
Pythagoras’ theorem. The third is the correction for the angle not
being a right angle: at C = 90°, cos 90° = 0, the term vanishes, and what is left is c² = a² + b².
So the law of cosines is not a second theorem standing beside Pythagoras but the general form of it —
Pythagoras is the special case.
The sign of the correction follows the angle. When C is acute the cosine is positive, the term is
subtracted, and c comes out shorter than Pythagoras would give. When C is obtuse the cosine is
negative, the minus becomes a plus, and c comes out longer. That matches the figure: open the angle
between two sticks and their far ends move apart.
Where it comes from
Drop a perpendicular from the corner at B onto side b. It splits the triangle into two right-angled
ones, and in the one containing angle C the height is a · sin C and the leg along the base is
a · cos C. The other triangle’s base is then b − a · cos C, and Pythagoras on it gives
c² = (a · sin C)² + (b − a · cos C)²
c² = a² sin²C + b² − 2ab · cos C + a² cos²C
Sine squared plus cosine squared is 1, so a² sin²C + a² cos²C is a², and the theorem is left
standing. The same working holds when C is obtuse: the foot of the perpendicular then falls outside the
side, a · cos C goes negative, and the subtraction takes care of itself.
Worked examples
The third side. Two sides are 5 cm and 8 cm with a 60° angle between them.
- c² = 5² + 8² − 2 · 5 · 8 · cos 60°
- c² = 25 + 64 − 80 · 0.5 = 89 − 40 = 49
- c = 7 cm
Compare with Pythagoras: without the correction the answer would have been √89 = 9.4 cm. An angle of
60° instead of 90° pulls the triangle in by 2.4 cm.
The angle from three sides. The same triangle backwards, given sides 5, 8 and 7:
- cos C = (a² + b² − c²) / 2ab
- cos C = (25 + 64 − 49) / 80 = 40 / 80 = 0.50
- C = arccos 0.50 = 60°
This arrangement is useful in practice. Three sides are what a tape measure gives you, and the law of
cosines is the direct route from three lengths to an angle.
Two answers. Now the awkward case: b = 8, c = 7 and C = 60°, with a unknown. Substitute and
collect:
- 49 = a² + 64 − 2 · a · 8 · 0.5
- a² − 8a + 15 = 0
- a = 4 ± √(16 − 15) = 4 ± 1
So a = 5 or a = 3. Both are real triangles. Check the smaller one: 9 + 64 − 2 · 3 · 8 · 0.5 = 73 − 24 = 49, as it should. Two different triangles share the same 60° angle and the same opposite side of 7 —
they differ only in how far the unknown side reaches — and nothing you were told decides between them. The
card above works out both and prints the second answer beside the first.
With an acute angle C, this happens when the opposite side c is shorter than the known side b but
longer than the height b · sin C. Here the height is 8 · sin 60° = 6.93, and 7 sits between 6.93 and 8. If c is shorter than
the height the side never reaches and there is no triangle; if c is longer than b there is exactly one.
Common mistakes
- Using the wrong angle.
C has to be the angle between a and b. An angle at some other corner
gives you a number, but not the right one. The check is easy: the side on the left must lie opposite the
angle on the right.
- Forgetting that
2ab · cos C is one term. Do not square the cosine, and do not multiply the 2 into
anything else. Work out 2 · a · b, multiply by cos C, subtract.
- Losing the minus sign at an obtuse angle.
cos 120° is −0.5, so the term becomes an addition. If a
third side comes out shorter than the other two despite an obtuse angle, you have probably dropped it.
- Reaching for the law of cosines when the law of sines would do. If you know a side and the angle
opposite it, the law of sines is a division rather than a quadratic.
- Answering with the larger root only. In the case above,
a = 3 is as correct as a = 5. Draw the
figure or find out more before choosing.
Frequently asked questions
When do I use the law of cosines and when the law of sines?
The law of cosines when you have two sides and the angle between them, or all three sides. The law of
sines when you have a side and the angle opposite it, plus one more thing. The rule of thumb: the law of
sines needs a pair — a side and its opposite angle — and if you have no such pair, the law of cosines is
your way in. Often you start with the law of cosines to get the first pair and continue with the
law of sines.
Can I use the law of cosines on a right triangle?
Yes, and you get Pythagoras back. Put C = 90°: cos 90° = 0, the last term is zero, and
c² = a² + b². Nothing wrong with doing it, just more keystrokes than you need.
Why do I sometimes get two answers and sometimes one?
Because the formula is a quadratic when the unknown side is one of the two that meet at the angle. The
square root can be added or subtracted, and both are triangles as long as both are positive lengths.
Solve instead for the opposite side c or the angle C and there is never more than one answer — those
arrangements are not quadratics.