The Law of Cosines: Derivation and When to Prefer It
The Law of Cosines looks, at first glance, like an arbitrary formula bolted onto the friendlier Law of Sines. It isn't. It falls directly out of the Pythagorean theorem the moment you drop a triangle onto a coordinate grid, and understanding that derivation makes both the formula and its special cases — including why it collapses to plain Pythagoras at a right angle — obvious rather than memorised. This walks through the derivation in full, then applies it to SAS and SSS triangles using the same solver behind the Law of Sines & Cosines Calculator.
Setting up the coordinates
Take a triangle with vertices A, B, and C, with the usual convention that side a is opposite A, b is opposite B, and c is opposite C. Place vertex C at the origin, and lay side b — the segment from C to A — along the positive x-axis, so A sits at the point (b, 0). Vertex B is a distance a from C (since side a is the segment CB), at an angle C measured from the x-axis, so B sits at (a cos C, a sin C). Every other side and angle now has coordinates to work with.
Applying the distance formula
Side c is the straight-line distance between A at (b, 0) and B at (a cos C, a sin C). The distance formula (itself just the Pythagorean theorem applied to the horizontal and vertical gap between two points) gives:
c2 = (b − a cos C)2 + (a sin C − 0)2.
Expanding the first term: (b − a cos C)2 = b2 − 2ab cos C + a2cos2C. Adding the second term, a2sin2C, gives:
c2 = b2 − 2ab cos C + a2cos2C + a2sin2C = b2 − 2ab cos C + a2(cos2C + sin2C).
The Pythagorean identity collapses cos2C + sin2C to exactly 1, leaving:
c2 = a2 + b2 − 2ab cos C.
That is the Law of Cosines, in full, with nothing hidden or asserted along the way — every step is either the distance formula, basic algebra, or the Pythagorean identity. Relabelling which vertex sits at the origin produces the same formula for the other two angles: a2 = b2 + c2 − 2bc cos A, and b2 = a2 + c2 − 2ac cos B.
Why it reduces to Pythagoras at 90°
The derivation makes the right-angle case transparent rather than a fact to memorise separately. When C = 90°, cos C = cos 90° = 0, and the entire −2ab cos C term vanishes on its own, leaving c2 = a2 + b2 exactly. The Law of Cosines is not a different formula that happens to agree with Pythagoras in a special case — it is Pythagoras, with an extra correction term that only activates when the angle drifts away from 90°. That correction term is also self-signing in a useful way: cos C is positive for an acute C (making c smaller than the plain sum a2 + b2 would suggest) and negative for an obtuse C (making c larger), which matches the geometric intuition that a wider angle stretches the opposite side out.
A second route: vectors and the dot product
The coordinate derivation above is not the only path to the same formula, and seeing a second route builds confidence that the result isn't an accident of how the axes happened to be drawn. Treat sides a and b as vectors u and v pointing out from vertex C, so side c is the vector u − v connecting their tips. The squared length of any vector difference expands as |u − v|2 = |u|2 + |v|2 − 2u·v, a standard vector identity. Since |u| = a, |v| = b, and the dot product u·v = ab cos C by definition (the angle between the two vectors is exactly C), substituting gives c2 = a2 + b2 − 2ab cos C — the identical formula, reached without ever setting up x and y coordinates explicitly. Both derivations are really the same argument in different clothing, since the coordinate version is what the dot product looks like once you write everything out component by component.
Worked example: SAS
Take b = 5, c = 7, with the included angle A = 40° between them. This is SAS — the angle sits between the two known sides — so the Law of Cosines solved for the missing side opposite that angle applies directly:
a2 = b2 + c2 − 2bc cos A = 52 + 72 − 2 × 5 × 7 × cos 40° = 25 + 49 − 70 × 0.766 ≈ 74 − 53.62 = 20.38,
so a = √20.38 ≈ 4.5141. With one full side-angle pair now available (a and A), the Law of Sines finishes the job: sin B = b sin A / a ≈ 5 × 0.6428 / 4.5141 ≈ 0.7120, giving B ≈ 45.4°, and C = 180° − 40° − 45.4° = 94.6°. The calculator's output matches exactly: a ≈ 4.5141, B ≈ 45.4°, C ≈ 94.6°, area ≈ 11.2488, perimeter ≈ 16.5141. Note there is no ambiguity to check here at all — unlike SSA, SAS never produces a second candidate triangle, because the Law of Cosines' inverse (arccos) is one-to-one across the full 0°-to-180° range a triangle's angle can take.
Worked example: SSS
Now take all three sides with no angle at all: a = 10, b = 14, c = 17. Rearranged to solve for an angle, the Law of Cosines becomes:
cos A = (b2 + c2 − a2) / (2bc) = (196 + 289 − 100) / (2 × 14 × 17) = 385 / 476 ≈ 0.8088,
so A = cos−1(0.8088) ≈ 36.02°. Repeating the pattern for B: cos B = (a2 + c2 − b2) / (2ac) = (100 + 289 − 196) / (2 × 10 × 17) = 193/340 ≈ 0.5676, so B ≈ 55.41°, and C = 180° − 36.02° − 55.41° ≈ 88.57°. The calculator confirms A ≈ 36.02°, B ≈ 55.41°, C ≈ 88.57°, area ≈ 69.9781, perimeter = 41. As with any SSS triangle, there was never a matched angle-side pair to hand the Law of Sines, so the Law of Cosines had to go first regardless of which angle you wanted.
The right-angle check, confirmed numerically
The reduction to Pythagoras claimed above is easy to confirm on a known right triangle. Solving the classic 3-4-5 triangle as SSS (a = 3, b = 4, c = 5, with no angle given) returns C = 90° exactly, along with A ≈ 36.87° and B ≈ 53.13°. Plugging C = 90° back into the general formula, cos C = cos 90° = 0, and indeed c2 = a2 + b2 − 2ab(0) = a2 + b2 = 9 + 16 = 25 = 52, exactly matching the Pythagorean theorem with no approximation involved anywhere in the check.
The sign of the correction term, confirmed
The claim earlier that cos C flips sign past 90° and stretches c accordingly is easy to see directly with a clearly obtuse example. Solving a = 5, b = 7, c = 11 as SSS returns a distinctly obtuse C ≈ 132.18°, and cos 132.18° ≈ −0.6715 — solidly negative, as expected well past 90°. That makes the correction term −2ab cos C in c2 = a2 + b2 − 2ab cos C work out to +47.0 (a negative cosine, multiplied by the leading minus sign, flips positive), so c2 = 74 + 47.0 = 121 = 112, exactly matching the given c = 11 — and substantially larger than a2 + b2 = 74 alone. That gap between 74 and 121 is the correction term earning its keep: the wide 132.18° angle physically forces the side opposite it to be much longer than a right angle between the same two sides would produce, and the size of that stretch is precisely what −2ab cos C measures.
Why SAS and SSS never carry SSA's risk
It is worth being explicit about why the ambiguity covered in The Law of Sines and the Ambiguous SSA Case never touches SAS or SSS. Inverse sine is not one-to-one over a triangle's possible angle range (0° to 180°) because sin θ = sin(180° − θ), so the same sine value maps back to two different angles in that range. Inverse cosine has no such problem: cos θ is strictly decreasing across the entire 0°-to-180° range, so every cosine value between −1 and 1 maps back to exactly one angle. Since SAS and SSS both solve for their first unknown using the Law of Cosines rather than the Law of Sines, that unique-inverse property carries straight through to the final answer — there is structurally no room for a second candidate triangle to sneak in.
When to prefer cosines over sines
Putting it plainly: reach for the Law of Cosines whenever you have all three sides (SSS) or two sides with the angle trapped between them (SAS), since in both cases there is no angle-side pair available for the Law of Sines to use as a starting point. Reach for it even when the Law of Sines is technically available, if avoiding the SSA ambiguity check matters more than a slightly longer calculation — for instance, a triangle with two sides and an angle can sometimes be re-framed as SAS by finding the included angle a different way first. And always reach for it to double-check a suspicious result: the right-angle reduction above means any SSS or SAS solution can be spot-checked against Pythagoras whenever one of the resulting angles lands near 90°.
Try both derivations yourself on the calculator, and see Law of Sines vs Law of Cosines for the full five-case decision guide these two worked examples slot into.