Search the complete library

What do you want to learn or calculate?

Quick linksAll calculatorsMath subjectsPractice questionsFormula library
← Trigonometry formulas

Law of cosines

Solve a triangle from SSS or SAS information.

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

Law of cosines is one of 3 triangles formulas in the trigonometry section of this library, and it is used at high school level.

Why law of cosines works

Split the triangle with a perpendicular and apply the Pythagorean theorem to both pieces. The extra horizontal distance you pick up equals b cos C, and squaring it produces the −2ab cos C correction. So this is the Pythagorean theorem plus a penalty term that measures how far angle C is from square.

What each symbol means

$C$ is included between sides $a,b$ and opposite side $c$.

Law of cosines: when it holds

Match each angle with its opposite side; the Pythagorean theorem is the $C=90^\circ$ case.

When it stops applying

Rearranged to find an angle, it can return a cosine outside the range −1 to 1, which means no triangle exists. With sides 2, 3, and 10, cos C works out to −7.25, and the honest reading is that a side of 10 is too long for legs of 2 and 3 to reach around.

Law of cosines: a worked example

For $a=5,b=7,C=60^\circ$, $c=\sqrt{25+49-35}=\sqrt{39}$.

The mistake to avoid

What people do: Students pair the angle with the wrong side, using an angle that is not across from the side they are solving for.

Why it goes wrong: The formula only balances when C sits between sides a and b and directly faces side c. Any other pairing computes a length that belongs to no triangle in the picture.

Do this instead: Circle the side you want, then find the angle staring straight at it. For a = 5, b = 7, and the angle between them C = 60 degrees, c² = 25 + 49 − 35 = 39, so c = √39, about 6.24.

Law of cosines: step by step

  1. Name the unknown, and the unit the answer has to come out in.
  2. Match the symbols to your values. $C$ is included between sides $a,b$ and opposite side $c$.
  3. Check the conditions before substituting. Match each angle with its opposite side; the Pythagorean theorem is the $C=90^\circ$ case.
  4. Substitute, keep exact values to the last line, then test the sign, size, and unit against a rough estimate — the check that catches most trigonometry slips.

Where this formula fits

Subject
Trigonometry formulas — 18 entries in this library
Topic
Triangles
Level
High school

Formulas are easiest to keep when they sit inside a method rather than on a list. Use the links below to see where law of cosines comes from, to check a calculation against a tool, and to practise it until you can recall it without looking.

Questions about law of cosines

Is the Pythagorean theorem just a special case of this?

Exactly. Put C = 90 degrees, so cos C is 0, the correction term disappears, and the equation collapses to c² = a² + b². The rest of the time that term adjusts for the angle being sharper or wider.

Why does this never produce the two-triangle ambiguity?

Because inverse cosine covers the whole span from 0 to 180 degrees, so it can hand back an obtuse angle directly. There is no missing second option to hunt for, which is why many people solve the largest angle with this rule first.

What does a negative cosine in my answer tell me?

That the angle is obtuse. A negative value means c² came out larger than a² + b², so the side across from C stretched beyond what a right angle would allow.

Can I use it when I only know two sides?

No. You need either all three sides or two sides plus the angle wedged between them. Two sides alone leave the hinge between them free to open to any width.

Stuck on a problem?

Work a law of cosines problem step by step

Type your own problem, or upload a photo of it. You get the method, the answer, and a check you can repeat yourself.