Audited ·Last updated 27 Jul 2026·5 citations·Tier 2·0 uses

Law of Cosines Calculator

Free law of cosines calculator: enter two sides and the included angle to find the third side, area, and perimeter, with full worked steps.

Law of Cosines Calculator

One of the two known sides, forming the included angle together with side b.
The other known side, forming the included angle together with side a.
The angle wedged between side a and side b — not the angle opposite either of them. Must be strictly between 0° and 180°.
Side c (opposite angle C)
6.245
The third side, computed as c = √(a² + b² − 2ab·cos C).
cos(C)
0.5
Area
15.1554
Perimeter
18.245

Background.

The law of cosines calculator solves the single most common oblique-triangle question there is: given two sides and the angle wedged between them, what is the length of the third side? Enter side a = 5, side b = 7, and an included angle of 60°, and the calculator returns c = √39 ≈ 6.245 in one step, along with the triangle's area and perimeter, using the formula c² = a² + b² − 2ab·cos(C) — the generalization of the Pythagorean theorem to triangles that don't have a right angle.

That generalization is exactly the reason the law of cosines matters. The Pythagorean theorem, a² + b² = c², only applies when the angle between a and b happens to be exactly 90°, which is a special case rather than the general rule. Most real triangles — a plot of land, a surveying triangle, a truss in a roof, a triangle formed by three cell towers — do not have a convenient right angle sitting inside them. The law of cosines removes that restriction entirely: subtract 2ab·cos(C) from a² + b², and the formula works for every triangle, acute, right, or obtuse, collapsing back to the familiar a² + b² = c² only when C happens to be 90° and cos(C) happens to be 0. This calculator makes that relationship visible directly — its worked example below can be re-run with the angle set to exactly 90° to reproduce the Pythagorean theorem's own 3-4-5 triangle, side for side.

This tool deliberately does one thing rather than several. Quanta already has a full triangle solver that handles SSS, SAS, and ASA input and returns every side, every angle, the area, and the perimeter in one pass — the right tool when you want the entire triangle solved regardless of which three measurements you started with. This calculator is narrower on purpose: it is the law of cosines itself, applied to the specific and extremely common "two sides and the angle between them" (SAS) case, returning the missing side directly along with the two quantities — area and perimeter — that fall out of the same three known inputs without any further trigonometry. If you need the two remaining angles as well, or you are working from three known sides instead and need to find an angle, the full triangle solver is the better tool, and it is linked from this page.

The angle you enter must be the included angle — the one sitting between the two sides you know, not the angle opposite either of them. Mixing that up is the single most common error when applying the law of cosines by hand, and it produces a triangle that looks plausible but is actually wrong, because the formula genuinely requires the angle between a and b, not some other angle in the figure. The calculator also enforces that the angle is strictly between 0° and 180°, since a 0° or 180° angle would collapse the triangle into a straight line with no interior area at all — a degenerate case rather than a genuine triangle.

What is law of cosines calculator?

The law of cosines is a formula relating the three sides of any plane triangle to the cosine of one of its angles: c² = a² + b² − 2ab·cos(C), where C is the angle opposite side c and is wedged directly between sides a and b. It generalizes the Pythagorean theorem, which is the special case where C = 90°: since cos(90°) = 0, the last term vanishes entirely and the formula reduces to c² = a² + b². For any other angle, the correction term 2ab·cos(C) accounts for how much the triangle deviates from having a right angle at C — subtracting when C is acute (cos C positive, making c shorter than the right-angle case) and adding when C is obtuse (cos C negative, making c longer). The relationship was known geometrically to Euclid, who proved both the obtuse and acute cases (Elements, Book II, Propositions 12 and 13) using areas of rectangles rather than trigonometric notation, centuries before the cosine function was formalized. Today the law of cosines is one of the two workhorse formulas of triangle trigonometry, alongside the law of sines, and it is the standard tool whenever a problem gives you two sides and the angle between them (SAS) and asks for the third side, or gives you all three sides (SSS) and asks for any angle.

How to use this calculator.

  1. Identify which angle is the included angle — the one physically between the two sides you know, not opposite either of them.
  2. Enter side a and side b, the two known sides.
  3. Enter the included angle C in degrees. It must be strictly between 0° and 180°.
  4. Read the primary result, side c — the missing side opposite the included angle.
  5. Read the area and perimeter outputs if you need them; both are fully determined by the same three inputs, no extra data required.
  6. If your included angle is exactly 90°, the result should match the Pythagorean theorem exactly — try the pythagorean calculator with the same two legs as a cross-check.
  7. If you know three sides instead of two sides and an angle, or you need every angle of the triangle as well as the side, use the triangle solver instead — this calculator is intentionally limited to the two-sides-and-included-angle case.

The formula.

c² = a² + b² − 2ab·cos(C)

The law of cosines can be derived by placing the included angle C at the origin of a coordinate system, with side b running along the positive x-axis. That puts one vertex at the origin, the vertex at the far end of side b at (b, 0), and the vertex at the far end of side a at (a·cos C, a·sin C), since side a makes angle C with side b. The unknown side c is exactly the distance between the two non-origin vertices, so by the standard distance formula, c² = (b − a·cos C)² + (a·sin C)². Expanding the first term gives b² − 2ab·cos C + a²cos²C, and adding a²sin²C to it gives a²cos²C + a²sin²C = a² (using the Pythagorean identity sin²C + cos²C = 1). Collecting everything: c² = a² + b² − 2ab·cos C — the law of cosines, derived purely from coordinates and the distance formula.

Once c is known, the perimeter is simply a + b + c, no further trigonometry required. The area does not even need c: with two sides and the angle between them already known, the area is (1/2)·a·b·sin(C) directly, the standard SAS area formula (the height of the triangle, dropped from the vertex where a and b meet down to the line containing side... more precisely, b·sin C is the height relative to base a, so (1/2)·base·height = (1/2)·a·(b sin C)).

The special case worth remembering is C = 90°: cos(90°) = 0, so the correction term 2ab·cos(C) disappears entirely and c² = a² + b² — exactly the Pythagorean theorem. That is not a coincidence or an approximation; the Pythagorean theorem is a strict special case of the law of cosines, true only when the included angle happens to be a right angle. For any acute included angle, cos(C) is positive, so c comes out shorter than the Pythagorean value with the same a and b. For any obtuse included angle, cos(C) is negative, so subtracting a negative term adds to the total, and c comes out longer.

A worked example.

Example

Two sides of a triangle measure 5 and 7 units, with an included angle of exactly 60° between them. Since cos(60°) = 0.5 exactly, the law of cosines gives c² = 5² + 7² − 2·5·7·0.5 = 25 + 49 − 35 = 39, so c = √39 ≈ 6.245 units. The area follows from the same three known values: (1/2)·5·7·sin(60°) = 17.5 × (√3/2) ≈ 15.155 square units. The perimeter is 5 + 7 + √39 ≈ 18.245 units. As a sanity check on the special case: if the included angle had been 90° instead of 60° with sides 3 and 4, cos(90°) = 0 makes the formula collapse to c² = 3² + 4² = 25, so c = 5 — exactly the Pythagorean theorem's classic 3-4-5 triangle, area 6, perimeter 12. That check is one of this page's automated test cases, and it is a fast way to confirm the formula is behaving correctly for the right-angle boundary case.

angle C60
side B7
side A5

Frequently asked questions.

What is the law of cosines?
The law of cosines is c² = a² + b² − 2ab·cos(C), a formula relating all three sides of a triangle to the cosine of one angle — specifically the angle C that sits opposite side c, between sides a and b. It is the standard tool for finding a missing side when you know two sides and the angle between them (SAS), or for finding a missing angle when you know all three sides (SSS). Unlike the simpler Pythagorean theorem, it applies to every triangle, not just right triangles, which is what makes it one of the two foundational formulas of triangle trigonometry alongside the law of sines.
How is the law of cosines related to the Pythagorean theorem?
The Pythagorean theorem is the special case of the law of cosines where the included angle C equals exactly 90°. Because cos(90°) = 0, the correction term −2ab·cos(C) vanishes entirely, leaving c² = a² + b² — the Pythagorean theorem exactly. For any other angle, that correction term is what makes the law of cosines work for non-right triangles: it shortens c when the angle is acute (cos C > 0) and lengthens c when the angle is obtuse (cos C < 0). You can verify this directly on this calculator by entering a right angle and comparing the result to the pythagorean calculator with the same two legs — the answers match exactly.
Why doesn't this calculator have an SSS mode for finding an angle from three sides?
Because Quanta's triangle solver already covers that case, along with SSS, SAS, and ASA modes that return every side, every angle, the area, and the perimeter in a single pass. Rather than duplicate that broader tool, this calculator focuses specifically on the two-sides-and-included-angle (SAS) case, which is the most common single-formula application of the law of cosines and matches what most people searching for a "law of cosines calculator" actually want: the missing side, quickly. If you know three sides and need an angle, or you want the full triangle solved from any combination of inputs, use the triangle solver instead.
What is the "included angle" and why does it have to be between the two known sides?
The included angle is the one physically wedged between the two sides you know — not the angle opposite either of them. This matters because the law of cosines formula c² = a² + b² − 2ab·cos(C) is only valid when C is genuinely the angle between sides a and b; plugging in the angle opposite a or opposite b instead produces a different, generally wrong, triangle. This is the single most common mistake when applying the law of cosines by hand. If the angle you actually have is opposite one of your known sides rather than between them, you have an SSA (not SAS) situation, and the law of cosines in this form does not directly apply — the law of sines, or the full triangle solver, is the better tool for that case.
What happens with an obtuse included angle?
The formula handles obtuse angles exactly as naturally as acute ones — there is no separate case to worry about. When C is obtuse, cos(C) is negative, so the term −2ab·cos(C) becomes positive, adding to a² + b² rather than subtracting from it. That produces a longer side c than you would get from a right or acute angle with the same a and b, which matches the geometry: a wide-open included angle pushes the two known sides' endpoints further apart. This calculator's test suite includes a 120° included-angle example (sides 6 and 8) specifically to confirm the obtuse case is handled correctly.
Why must the included angle be strictly between 0° and 180°?
Those are the only angle measures that describe a genuine triangle. An included angle of 0° would mean sides a and b point in the same direction, collapsing the triangle into a single line segment with no area. An included angle of 180° would mean they point in exactly opposite directions, which is equally degenerate — again a straight line, not a triangle. Any angle strictly between those two bounds describes a real, non-degenerate triangle, which is exactly the domain this calculator enforces, raising a clear error rather than returning a nonsensical or zero-area result for either boundary case.
Where does the law of cosines come from?
It follows directly from placing the triangle on a coordinate grid and applying the distance formula. Put the included angle C at the origin with side b running along the x-axis; the far end of side a then sits at coordinates (a·cos C, a·sin C) because side a makes angle C with side b. The unknown side c is the distance between that point and the far end of side b, and expanding that distance formula — using the identity sin²C + cos²C = 1 to simplify — produces exactly c² = a² + b² − 2ab·cos(C). Euclid proved the same relationship geometrically, without coordinates or trigonometric functions, roughly two thousand years before Descartes introduced coordinate geometry, in Book II of the Elements (Propositions 12 and 13, covering the obtuse and acute cases separately).

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 313 calculators remain free
  • No billing is enabled
Coming soon