Law of Cosines Calculator
The Law of Cosines solves triangles when you know two sides and the angle between them (SAS) or all three sides (SSS). Select a case below to get started.
The Law of Cosines
For a triangle with sides $a$, $b$, $c$ and opposite angles $A$, $B$, $C$:
$$c^2 = a^2 + b^2 - 2ab\cos C$$This is a generalization of the Pythagorean theorem: when $C = 90°$, $\cos C = 0$ and the formula reduces to $c^2 = a^2 + b^2$.
To find an angle from all three sides, rearrange:
$$\cos C = \frac{a^2 + b^2 - c^2}{2ab}$$SAS vs SSS — Which Do I Have?
| Case | Known | What you find |
|---|---|---|
| SAS | a, b, and angle C (between a and b) | Side c, then angles A and B |
| SSS | a, b, c | All three angles A, B, C |
If you have two angles and a side (AAS or ASA), or two sides and an angle opposite one of them (SSA), use the Law of Sines calculator instead. For right triangles, the right triangle calculator is simpler to use.
Worked Example: SAS
Triangle with $a = 8$, $b = 5$, $C = 60°$. Find $c$:
$$c^2 = 8^2 + 5^2 - 2(8)(5)\cos 60° = 64 + 25 - 80 \times 0.5 = 49$$ $$c = 7$$Frequently Asked Questions
Why does the Law of Cosines generalize the Pythagorean theorem?
When $C = 90°$, $\cos 90° = 0$. The $-2ab\cos C$ term vanishes, leaving $c^2 = a^2 + b^2$, which is exactly the Pythagorean theorem. You can think of $-2ab\cos C$ as a correction term that accounts for the triangle not being right-angled.
What if my triangle is obtuse?
No problem — the Law of Cosines works for acute, right, and obtuse triangles alike. When $C > 90°$, $\cos C$ is negative, so $-2ab\cos C$ becomes positive, making $c^2 > a^2 + b^2$, which is consistent with the obtuse side being opposite the longest side.
What is the triangle inequality?
Any valid triangle requires that the sum of any two sides must exceed the third: $a + b > c$, $a + c > b$, $b + c > a$. The calculator will detect invalid inputs that violate this rule.