Category

Law of Cosines Calculator

Formula

Enter your values

Enter your values and press Calculate — your answer, visual and step-by-step solution appear here.

What Is the Law of Cosines?

The law of cosines says that in any triangle, the square of one side equals the sum of the squares of the other two sides minus twice their product times the cosine of the angle between them. In symbols, with sides a, b, c and the angle C opposite side c:

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

Here side c sits opposite angle C, and C is the included angle — the angle formed between sides a and b. Unlike the Pythagorean theorem, this rule works for any triangle, not just right triangles, which makes it the go-to tool for oblique (non-right) triangles. This free law of cosines calculator applies the formula for you and shows every step. Need other tools? See all our free math calculators.

The Law of Cosines Formulas (All Three Sides + the Angle Form)

Because the labels a, b, and c are interchangeable, the law of cosines comes in three matching versions — one for each side paired with its opposite angle. Use the side form when you know two sides and the included angle (SAS):

a² = b² + c² − 2bc·cos A
b² = a² + c² − 2ac·cos B
c² = a² + b² − 2ab·cos C

When you already know all three sides and want to solve for an angle (the SSS workhorse), rearrange each formula to isolate the cosine:

cos A = (b² + c² − a²) / (2bc)
cos B = (a² + c² − b²) / (2ac)
cos C = (a² + b² − c²) / (2ab)

After computing the cosine, take the inverse cosine (arccos) of the result to recover the angle in degrees. The calculator's two modes mirror these exactly: the SAS mode uses the side form to find a missing side, and the SSS mode uses the angle form to find every angle. If you ever need a raw trig value on its own, the trig functions calculator evaluates sine, cosine, and tangent directly.

When to Use the Law of Cosines (vs. Law of Sines vs. Pythagoras)

The hardest part is usually deciding which rule fits your triangle. Match what you already know to the right method:

You knowUseWhy
2 sides + included angle (SAS)Law of cosinesDirectly gives the third side
3 sides (SSS)Law of cosinesGives any angle via the angle form
2 angles + a side (ASA / AAS)Law of sinesPairs each side with its opposite angle
2 sides + a non-included angle (SSA)Law of sines (ambiguous case)May yield 0, 1, or 2 triangles
A right trianglePythagorean theoremSpecial case where cos 90° = 0

The bridge to the law of sines is simple: if your known angle is not tucked between your two known sides, the law of cosines can't start cleanly, so you switch to the law of sines instead. The bridge to Pythagoras is even neater — a right triangle is just the law of cosines with a 90° angle, where the cosine term vanishes (covered below). For a step-by-step walk-through of the decision, see Law of Sines vs. Law of Cosines: when to use each.

How to Use This Law of Cosines Calculator

  1. Choose your mode. Pick SAS if you have two sides and the angle between them, or SSS if you have all three side lengths.
  2. Enter the known values. Type your two sides and included angle (SAS) or your three sides (SSS). Tap an example chip — such as 8, 5, 60° or 3, 4, 90° — for an instant demo.
  3. Press Calculate. A built-in triangle-inequality check first confirms your inputs can actually form a triangle and flags impossible ones.
  4. Read the results. The grid lists all three angles and sides, plus a sense-check (it verifies the longest side sits opposite the largest angle and classifies the triangle) and a to-scale diagram.
  5. Open Step-by-Step. Expand the Steps tab to see the full derivation worked line by line for either mode.

Worked Examples (Step by Step)

These two examples mirror exactly what the calculator produces — one for each mode.

SAS — find the third side

Given two sides and the angle between them: a = 8, b = 5, included angle C = 60°. Find side c.

  1. Write the side form. c² = a² + b² − 2ab·cos C.
  2. Substitute the values. c² = 8² + 5² − 2·8·5·cos 60°.
  3. Simplify. Since cos 60° = 0.5, this is c² = 64 + 25 − 80(0.5) = 89 − 40 = 49.
  4. Take the square root. c = √49 = 7.
Answer: the third side is c = 7.

SSS — find an angle from three sides

Given all three sides: a = 5, b = 7, c = 8. Find the angle C opposite the longest side.

  1. Write the angle form. cos C = (a² + b² − c²) / (2ab).
  2. Substitute the values. cos C = (5² + 7² − 8²) / (2·5·7) = (25 + 49 − 64) / 70.
  3. Simplify the fraction. cos C = 10 / 70 ≈ 0.1429.
  4. Take the inverse cosine. C = arccos(0.1429) ≈ 81.79°.
Answer: C ≈ 81.79°. Notice the largest angle is opposite the longest side (8) — exactly the sanity check the calculator performs.

An applied example

Two trails leave the same trailhead at an angle of 60° between them; one runs 8 km and the other 5 km. How far apart are their endpoints in a straight line? This is the SAS case above, so the gap is c = 7 km. The same calculation finds the straight-line distance across a lake or the separation between two flight paths.

How the Law of Cosines Generalizes the Pythagorean Theorem

The Pythagorean theorem is simply the law of cosines for a right triangle. When the included angle C = 90°, its cosine is zero (cos 90° = 0), so the final term disappears entirely:

c² = a² + b² − 2ab·cos 90° = a² + b² − 0 = a² + b²

That is the familiar Pythagorean theorem, a² + b² = c². In other words, the law of cosines is the more general rule, and Pythagoras is the special case it collapses to at 90°. The calculator's sense-check confirms this: feed it a right triangle and it flags the right angle and notes that Pythagoras would give the same answer. This relationship appears in any standard trigonometry or precalculus textbook.

Real-World Uses of the Law of Cosines

The Ambiguous Case and Why This Calculator Uses SAS & SSS

SAS and SSS each lock in exactly one triangle, so the answer is always unique — that is why this tool is built around those two inputs. The trouble spot is SSA (two sides and a non-included angle), known as the ambiguous case: depending on the numbers it can produce zero, one, or two valid triangles. Because the answer isn't unique, the law of cosines (and this calculator) deliberately stays with the unambiguous SAS and SSS cases.

Have an SSA problem? Switch to the law of sines, which handles the ambiguous case and tells you whether you have one triangle or two. Our ambiguous case guide shows how to count the triangles and find the second one.

Common Mistakes

Mistake — using a non-included angleThe angle in c² = a² + b² − 2ab·cos C must be the angle between sides a and b (opposite c). Plugging in an angle that touches only one of those sides gives a wrong answer — that situation calls for the law of sines instead.
Mistake — forgetting the square root at the endThe side form gives you c², not c. After computing 49, you still must take √49 = 7. Reporting 49 as the side length is a classic slip.
Mistake — order of operations on the cosine termCompute 2ab·cos C as a single product before subtracting. Squaring the sides and multiplying by the cosine, then mixing up what to add versus subtract, is where most arithmetic errors creep in.
Mistake — calculator in radian modeIf your angles are in degrees, your calculator must be in degree mode. cos 60° = 0.5, but cos(60 radians) ≈ −0.95 — a silent error that ruins the result.
Mistake — skipping the triangle-inequality checkFor SSS, each side must be shorter than the sum of the other two. Inputs like 2, 3, 10 describe no real triangle, and arccos will return an error — which is exactly what the "invalid triangle" message is telling you.
Need a calculator for class? The TI-84 Plus CE is one of the most widely used graphing calculators for trigonometry, precalculus, and calculus coursework. View on Amazon →
As an Amazon Associate, MathInSite earns from qualifying purchases.

Frequently Asked Questions