Use the law of cosines when a triangle is not right and you know either two sides with the included angle or all three sides. For sides aa, bb, cc opposite angles AA, BB, CC, the standard form is

c2=a2+b22abcosCc^2 = a^2 + b^2 - 2ab\cos C

Here, side cc is opposite angle CC, and CC is the angle between sides aa and bb. The same pattern works for the other sides:

a2=b2+c22bccosAa^2 = b^2 + c^2 - 2bc\cos A b2=a2+c22accosBb^2 = a^2 + c^2 - 2ac\cos B

If C=90C = 90^\circ, then cosC=0\cos C = 0, so the formula becomes c2=a2+b2c^2 = a^2 + b^2. That is why the law of cosines is a generalization of the Pythagorean theorem.

When to use the law of cosines

The most common setup is SAS: two sides and the included angle. The included angle means the angle formed by those two known sides.

It also works for SSS: all three sides are known, and you want an angle. In that case, rearrange the formula before using inverse cosine.

If you already know a side and its opposite angle, the law of sines is often the better first tool.

What the formula means

If two sides stay fixed, the third side depends on the angle between them.

When the included angle gets larger, the opposite side gets longer. When the angle gets smaller, the opposite side gets shorter. The term 2abcosC-2ab\cos C adjusts the simple sum a2+b2a^2 + b^2 to account for that angle.

That correction term is the part people should remember. Without it, you would be treating every triangle like a right triangle.

Worked example: find a side

Suppose a triangle has sides a=5a = 5 and b=7b = 7, and the included angle is C=60C = 60^\circ. Find side cc.

Because cc is opposite the known angle CC, use

c2=a2+b22abcosCc^2 = a^2 + b^2 - 2ab\cos C

Substitute the values:

c2=52+722(5)(7)cos60c^2 = 5^2 + 7^2 - 2(5)(7)\cos 60^\circ

Since cos60=12\cos 60^\circ = \frac{1}{2},

c2=25+4970(12)=7435=39c^2 = 25 + 49 - 70\left(\frac{1}{2}\right) = 74 - 35 = 39

So

c=396.24c = \sqrt{39} \approx 6.24

That answer makes sense: the third side is longer than 55 but shorter than 7+5=127 + 5 = 12, and the angle is moderate rather than extremely large.

How to find an angle from three sides

If all three sides are known, solve for the cosine first:

cosC=a2+b2c22ab\cos C = \frac{a^2 + b^2 - c^2}{2ab}

Then compute

C=cos1(a2+b2c22ab)C = \cos^{-1}\left(\frac{a^2 + b^2 - c^2}{2ab}\right)

This only makes sense when aa, bb, and cc form a valid triangle. If the value inside cos1\cos^{-1} is outside the interval [1,1][-1, 1], there is an earlier algebra or data error.

A short proof idea

One clean proof comes from coordinates.

Place one side on the xx-axis. Let one vertex be at (0,0)(0, 0) and another at (b,0)(b, 0). Put the third vertex at (acosC,asinC)(a\cos C, a\sin C) because that point is distance aa from the origin and makes angle CC with the xx-axis.

Now use the distance formula between (b,0)(b, 0) and (acosC,asinC)(a\cos C, a\sin C):

c2=(bacosC)2+(0asinC)2c^2 = (b - a\cos C)^2 + (0 - a\sin C)^2

Expand:

c2=b22abcosC+a2cos2C+a2sin2Cc^2 = b^2 - 2ab\cos C + a^2\cos^2 C + a^2\sin^2 C

Then use

sin2C+cos2C=1\sin^2 C + \cos^2 C = 1

to combine the last two terms:

c2=a2+b22abcosCc^2 = a^2 + b^2 - 2ab\cos C

That is the law of cosines.

Common mistakes

Matching the wrong side and angle

The angle in the formula must be opposite the side on the left side of the equation. If you use angle CC, then the left side must be c2c^2.

Using the formula as if every triangle were right

If the angle is not 9090^\circ, you cannot drop the 2abcosC-2ab\cos C term.

Forgetting calculator mode

If the problem gives degrees, your calculator must be in degree mode. If it gives radians, use radian mode.

Solving for an angle without isolating cosine carefully

When all three sides are known, rearrange first, then use inverse cosine. A small algebra mistake there can push the final angle off by a lot.

Where the law of cosines is used

The law of cosines is common in geometry, trigonometry, surveying, navigation, and any problem where you need distances in a non-right triangle.

In school math, the two main uses are:

  • finding a missing side from two sides and the included angle
  • finding a missing angle from all three sides

If you already have a right triangle, the Pythagorean theorem is usually the simpler version. If you know angles with a side pair instead, the law of sines may be a better fit.

Try your own version

Take a=8a = 8, b=11b = 11, and C=30C = 30^\circ, then find cc. After that, change CC to 120120^\circ and compare the result. Watching the opposite side grow is one of the fastest ways to make the formula feel intuitive.

If you want step-by-step feedback with your own numbers, explore a similar triangle in GPAI Solver.

Need help with a problem?

Upload your question and get a verified, step-by-step solution in seconds.

Open GPAI Solver →