Law of Cosines : Formula, Proof, and Examples

#Trigonometry
TL;DR
The law of cosines states $c^2 = a^2 + b^2 - 2ab\cos C$, relating the three sides of any triangle to the cosine of one angle. This article covers when to use it (the SAS and SSS cases), its derivation, six worked examples, how it generalises the Pythagorean theorem, and the errors students make with obtuse angles.
BT
Bhanzu TeamLast updated on August 12, 202610 min read

The Rule That Fixes A Triangle You Can't Fully See

Give a navigator two sides and the angle between them, and the third side is fixed. No right angle is needed, no measuring tape reaches across the gap — the law of cosines turns two known distances and the angle between them into the exact length of the third. Surveyors, pilots, and GPS receivers all rely on it to close a triangle they can only partly measure.

The law of cosines does what the Pythagorean theorem cannot: it works for any triangle, not just right-angled ones. It relates all three sides to the cosine of one angle, which is why it sits at the centre of triangle-solving alongside the law of sines.

What Is The Law Of Cosines?

The law of cosines is an equation that holds for every triangle. For a triangle with sides $a$, $b$, $c$ and the angle $\angle C$ opposite side $c$:

$$c^2 = a^2 + b^2 - 2ab\cos C$$

By symmetry, the same relationship rotates around the triangle:

$$a^2 = b^2 + c^2 - 2bc\cos A$$

$$b^2 = a^2 + c^2 - 2ac\cos B$$

In each version, the side on the left is opposite the angle on the right. The angle $\angle C$ is the included angle - the one squeezed between the two sides $a$ and $b$. The cosine here is the ordinary cosine ratio from the sin cos tan family, evaluated at the triangle's angle. Because the law works on every triangle, not only right-angled ones, it applies across all types of triangles - acute, right, and obtuse.

How Does It Extend The Pythagorean Theorem?

Set $\angle C = 90^\circ$. Then $\cos 90^\circ = 0$, and the correction term $-2ab\cos C$ vanishes:

$$c^2 = a^2 + b^2 - 2ab(0) = a^2 + b^2$$

That is exactly the Pythagorean theorem for a right-angled triangle. So the law of cosines is the Pythagorean theorem with one extra term that measures how far the triangle bends away from a right angle. When $\angle C$ is acute, $\cos C > 0$ and the term shrinks $c$; when $\angle C$ is obtuse, $\cos C < 0$ and the term grows $c$.

How Do You Derive The Law Of Cosines?

The clearest derivation drops the triangle onto a coordinate grid. Place vertex $C$ at the origin, with side $b$ along the positive $x$-axis, so vertex $A$ sits at $(b, 0)$. The angle $\angle C$ opens from the $x$-axis, so vertex $B$ has coordinates found from the cosine and sine of $\angle C$:

$$B = (a\cos C, ; a\sin C)$$

Side $c$ is the distance from $A(b, 0)$ to $B(a\cos C, a\sin C)$. Apply the distance formula:

$$c^2 = (a\cos C - b)^2 + (a\sin C - 0)^2$$

Expand each square, one line at a time:

$$c^2 = a^2\cos^2 C - 2ab\cos C + b^2 + a^2\sin^2 C$$

Group the two $a^2$ terms and use the identity $\cos^2 C + \sin^2 C = 1$:

$$c^2 = a^2(\cos^2 C + \sin^2 C) + b^2 - 2ab\cos C$$

$$c^2 = a^2 + b^2 - 2ab\cos C$$

The coordinate placement is what makes the enclosed angle $\angle C$ carry all the weight, and the Pythagorean identity is what collapses the sine and cosine terms into a clean result.

When Do You Use The Law Of Cosines?

The law of cosines solves two of the standard triangle cases. Knowing which case you are in is the whole skill.

  • SAS - two sides and the included angle. You know $a$, $b$, and $\angle C$, and you want the third side $c$. Plug straight into $c^2 = a^2 + b^2 - 2ab\cos C$.

  • SSS - all three sides. You know $a$, $b$, $c$ and want an angle. Rearrange the formula: $\cos C = \dfrac{a^2 + b^2 - c^2}{2ab}$, then take the inverse cosine.

If instead you know two angles and a side, or a side-side-angle pair, reach for the law of sines - that is its territory. A quick way to decide: if the known angle sits between the two known sides, the law of cosines is the tool.

Examples Of The Law Of Cosines

Example 1

A triangle has $a = 5$, $b = 7$, and included angle $\angle C = 60^\circ$. Find side $c$.

$$c^2 = a^2 + b^2 - 2ab\cos C = 25 + 49 - 2(5)(7)\cos 60^\circ$$

$$c^2 = 74 - 70(0.5) = 74 - 35 = 39$$

$$c = \sqrt{39} \approx 6.24$$

Final answer: $c = \sqrt{39} \approx 6.24$.

Example 2

A triangle has $a = 6$, $b = 10$, and included angle $\angle C = 120^\circ$. Find side $c$. First instinct, then the correct route.

The common slip is to read $\cos 120^\circ$ as $+0.5$, forgetting the quadrant sign:

$$c^2 = 36 + 100 - 2(6)(10)(0.5) = 136 - 60 = 76, \quad c \approx 8.72$$

Check that against the triangle. The angle $\angle C = 120^\circ$ is obtuse, so side $c$, opposite the largest angle, must be the longest side, longer than $b = 10$. An answer of $8.72$ is shorter than $10$, which is impossible.

The fix is the sign. In the second quadrant $\cos 120^\circ = -0.5$:

$$c^2 = 136 - 2(6)(10)(-0.5) = 136 + 60 = 196$$

$$c = \sqrt{196} = 14$$

Now $c = 14 > 10$, exactly as an obtuse triangle demands.

Final answer: $c = 14$.

Example 3

A triangle has sides $4$, $5$, $6$. Find its largest angle.

The largest angle sits opposite the longest side, $6$. Solve for $\angle C$ with $c = 6$, $a = 4$, $b = 5$:

$$\cos C = \frac{a^2 + b^2 - c^2}{2ab} = \frac{16 + 25 - 36}{2(4)(5)} = \frac{5}{40} = 0.125$$

$$C = \cos^{-1}(0.125) \approx 82.8^\circ$$

Final answer: the largest angle is about $82.8^\circ$, which is acute, not the right angle a quick guess might assume.

Example 4

Confirm the Pythagorean reduction: a triangle with $a = 3$, $b = 4$, $\angle C = 90^\circ$.

$$c^2 = 9 + 16 - 2(3)(4)\cos 90^\circ = 25 - 24(0) = 25$$

$$c = 5$$

Final answer: $c = 5$, the familiar 3-4-5 right triangle, recovered from the law of cosines.

Example 5

Two straight roads leave a junction at an angle of $100^\circ$. A car drives $12$ km down one and $9$ km down the other. How far apart are the endpoints?

$$d^2 = 12^2 + 9^2 - 2(12)(9)\cos 100^\circ = 144 + 81 - 216(-0.1736)$$

$$d^2 = 225 + 37.5 = 262.5, \quad d \approx 16.2 \text{ km}$$

Final answer: the endpoints are about $16.2$ km apart.

Example 6

A triangle has sides $7$, $8$, $9$. Find the angle opposite the side of length $9$.

$$\cos C = \frac{7^2 + 8^2 - 9^2}{2(7)(8)} = \frac{49 + 64 - 81}{112} = \frac{32}{112} \approx 0.2857$$

$$C = \cos^{-1}(0.2857) \approx 73.4^\circ$$

Final answer: the angle is about $73.4^\circ$.

Where Does The Law Of Cosines Earn Its Keep? - "Closing a triangle nobody can walk across"

The law of cosines exists to measure a distance you cannot reach with a ruler. Give it two sides and the angle between them, and it hands back the third side exactly.

  • Navigation and dead reckoning. A ship that sails one leg, turns through a known angle, and sails another can compute its straight-line distance from the start without any landmark - pure triangle-solving.

  • Surveying and GPS. Land surveyors and satellite receivers fix a point by relating measured distances and angles; the law of cosines converts those raw measurements into positions.

  • Engineering and structures. Truss members meeting at non-right angles have lengths and joint angles bound by the law of cosines, so a designer can size a diagonal from the two members it connects.

Why does the correction term carry a minus sign? Because a wider enclosed angle pushes the far vertex apart, and the cosine - positive for acute angles, negative for obtuse - measures exactly that spread. The formula and the geometry are the same statement, which is documented in full at Wolfram MathWorld.

The Mathematicians Behind The Law Of Cosines

Euclid (c. 300 BC, Alexandria) proved the geometric ancestor of the law in Elements Propositions II.12 and II.13, stating the acute and obtuse cases as area relationships without trigonometry. Jamshīd al-Kāshī (c. 1380–1429, Persia) recast those results into the numerical, cosine-based form used today, which is why the rule is called Al-Kashi's theorem in France; his biography sits at MacTutor.

Common Mistakes With The Law Of Cosines

Mistake 1: Dropping The Sign On An Obtuse Angle

Where it slips in: Any SAS problem where the included angle is more than $90^\circ$.

Don't do this: Using $\cos 120^\circ = +0.5$. In the second quadrant, cosine is negative.

The correct way: $\cos 120^\circ = -0.5$, which flips the correction term from subtracting to adding and lengthens the opposite side. The check that saves you: the side opposite an obtuse angle is always the longest, so an answer shorter than its neighbours signals a sign error. The rusher who plugs in the reference-angle cosine without checking the quadrant lands here most often.

Mistake 2: Pairing The Wrong Side With The Angle

Where it slips in: Setting up the formula when the labels $a$, $b$, $c$ are not the ones in the diagram.

Don't do this: Writing $c^2 = a^2 + b^2 - 2ab\cos A$, using the angle that is not opposite side $c$.

The correct way: The side on the left must be opposite the angle on the right. Match $c$ with $\angle C$, $a$ with $\angle A$, $b$ with $\angle B$ every time. The memorizer who recites one version of the formula but never re-labels the triangle produces a right-looking equation that solves the wrong triangle.

Mistake 3: Adding Instead Of Subtracting The Correction Term

Where it slips in: Rushing the arithmetic of $-2ab\cos C$.

Don't do this: Computing $a^2 + b^2 + 2ab\cos C$ for an acute angle.

The correct way: The term is subtracted: $-2ab\cos C$. A sign error here is the trigonometric cousin of a dead-reckoning slip - the same class of arithmetic mistake that has put ships and aircraft off their plotted course, where a wrong intermediate value quietly compounds into a real position error. Keep the minus sign attached and evaluate the cosine last.

Key Takeaways

  • The law of cosines is $c^2 = a^2 + b^2 - 2ab\cos C$, valid for every triangle.

  • Use it for SAS (find the third side) and SSS (find an angle).

  • It generalises the Pythagorean theorem: at $\angle C = 90^\circ$ the cosine term disappears.

  • For an obtuse included angle the cosine is negative, which lengthens the opposite side.

  • Match each side to the angle opposite it, and keep the minus sign on the $2ab\cos C$ term.

To work through the law of cosines with a teacher, explore Bhanzu's trigonometry tutor sessions, a high school math tutor for triangle-solving practice, or live math classes online with peers from 20+ countries.

A Practical Next Step

Practice these to solidify your understanding: solve a triangle with $a = 8$, $b = 6$, $\angle C = 110^\circ$ for side $c$, then use the SSS rearrangement to recover $\angle C$ from your three sides. If the obtuse sign trips you up, come back to the properties section above. Want a live Bhanzu trainer to solve triangles with you? Book a free demo class.

Read More

Book a Free Demo

Was this article helpful?

Your feedback helps us write better content

Frequently Asked Questions

What is the law of cosines formula?
$c^2 = a^2 + b^2 - 2ab\cos C$, with $c$ the side opposite angle $\angle C$. The formula rotates for the other sides and angles.
When should I use the law of cosines instead of the law of sines?
Use the law of cosines for SAS (two sides and the included angle) or SSS (three sides). Use the law of sines when you know two angles and a side, or a side-side-angle pair.
Does the law of cosines work for right triangles?
Yes. When the angle is $90^\circ$, $\cos 90^\circ = 0$ and the formula reduces to the Pythagorean theorem $c^2 = a^2 + b^2$.
How do I find an angle with the law of cosines?
Rearrange to $\cos C = \dfrac{a^2 + b^2 - c^2}{2ab}$, then take the inverse cosine. This is the SSS case.
Who discovered the law of cosines?
Its geometric form goes back to Euclid; the modern cosine-based statement was developed by the Persian mathematician Al-Kāshī in the 15th century.
✍️ Written By
BT
Bhanzu Team
Content Creator and Editor
Bhanzu’s editorial team, known as Team Bhanzu, is made up of experienced educators, curriculum experts, content strategists, and fact-checkers dedicated to making math simple and engaging for learners worldwide. Every article and resource is carefully researched, thoughtfully structured, and rigorously reviewed to ensure accuracy, clarity, and real-world relevance. We understand that building strong math foundations can raise questions for students and parents alike. That’s why Team Bhanzu focuses on delivering practical insights, concept-driven explanations, and trustworthy guidance-empowering learners to develop confidence, speed, and a lifelong love for mathematics.
Related Articles
Book a FREE Demo ClassBook Now →