Trigonometry

Law of Cosines: Formula, Proof, and How to Use It

The law of cosines says c2=a2+b2−2abcos⁡Cc^2 = a^2 + b^2 - 2ab\cos C, where CC is the angle opposite side cc. It finds a missing side when you know two sides and the angle between them, and a missing angle when you know all three sides.

c2=a2+b2−2abcos⁡Cc^2 = a^2 + b^2 - 2ab\cos C

Try it with your numbers

Show every step

Right-triangle ratios from SOH CAH TOA stop working the moment a triangle has no right angle. The law of cosines is the Pythagorean theorem with one correction term attached, and that term is the whole story.

What is the law of cosines and when do you use it?

Label the triangle so that side aa faces angle AA, side bb faces angle BB and side cc faces angle CC. The law then comes in three matching versions, one per side:

  • a2=b2+c2−2bccos⁡Aa^2 = b^2 + c^2 - 2bc\cos A
  • b2=a2+c2−2accos⁡Bb^2 = a^2 + c^2 - 2ac\cos B
  • c2=a2+b2−2abcos⁡Cc^2 = a^2 + b^2 - 2ab\cos C

The pattern never changes: the side on the left and the angle inside the cosine are opposite each other, and the other two sides appear squared and then multiplied together. Students who mix up which angle goes where almost always have a sketch with unlabeled or mislabeled opposite pairs, so draw the triangle first.

The law is for two situations. If you know two sides and the included angle (the angle between them, called SAS), it gives the third side. If you know all three sides (SSS), solve the formula for the cosine and it gives any angle:

cos⁡C=a2+b2−c22ab\cos C = \frac{a^2 + b^2 - c^2}{2ab}

If you instead know two angles and a side, the law of sines is the shorter route.

Quick check

You know sides b=6b = 6 and c=9c = 9 and the angle A=40∘A = 40^\circ between them. Which side can you find directly with the law of cosines?

Where does the law of cosines come from?

The whole proof is the distance formula plus one identity. Put angle CC at the origin, lay side aa along the positive xx-axis so that B=(a,0)B = (a, 0), and then vertex AA sits at (bcos⁡C, bsin⁡C)(b\cos C,\ b\sin C). Side cc is the distance between AA and BB:

c2=(bcos⁡C−a)2+(bsin⁡C)2c^2 = (b\cos C - a)^2 + (b\sin C)^2

Expand the squares and collect terms:

c2=b2cos⁡2C−2abcos⁡C+a2+b2sin⁡2C=a2+b2−2abcos⁡Cc^2 = b^2\cos^2 C - 2ab\cos C + a^2 + b^2\sin^2 C = a^2 + b^2 - 2ab\cos C

The last step uses sin⁡2C+cos⁡2C=1\sin^2 C + \cos^2 C = 1, one of the Pythagorean identities, to merge the two b2b^2 terms.

What the correction term means

The quantity bcos⁡Cb\cos C is how far vertex AA sits along side aa (its shadow). The term −2abcos⁡C-2ab\cos C adjusts the Pythagorean sum for that lean: positive cosine shrinks cc, negative cosine stretches it.

This also explains why no triangle-specific trick is needed. Any triangle can be rotated so one angle sits at the origin, so the formula holds for every triangle, acute or obtuse.

How do you find a missing side with the law of cosines?

Take a=7a = 7, b=10b = 10 and the included angle C=35∘C = 35^\circ. Side cc is opposite CC, so use the version with cos⁡C\cos C:

c2=72+102−2(7)(10)cos⁡35∘c^2 = 7^2 + 10^2 - 2(7)(10)\cos 35^\circ

Evaluate the product 140cos⁡35∘140\cos 35^\circ first: 140×0.81915≈114.68140 \times 0.81915 \approx 114.68. Then c2=149−114.68=34.32c^2 = 149 - 114.68 = 34.32, and finally c=34.32≈5.86c = \sqrt{34.32} \approx 5.86.

Three traps cost most of the points here. First, subtracting before multiplying: (a2+b2−2ab)cos⁡C(a^2 + b^2 - 2ab)\cos C is a different, wrong expression, because 2abcos⁡C2ab\cos C must be computed as a single product. Second, stopping at c2c^2 and forgetting the square root. Third, a calculator in the wrong mode: with the angle in degrees, the calculator must be in degree mode, and if the problem gives radians, convert with degrees to radians or radians to degrees first.

A fast reasonableness check: with a=7a = 7 and b=10b = 10, the third side must land between 33 and 1717, and a 35∘35^\circ angle is narrow, so a result near the low end like 5.865.86 makes sense.

How do you find an angle with the law of cosines?

Take a triangle with sides 77, 88 and 99. Start with the largest angle, the one opposite 99, and call it CC:

cos⁡C=72+82−922(7)(8)=32112=27\cos C = \frac{7^2 + 8^2 - 9^2}{2(7)(8)} = \frac{32}{112} = \frac{2}{7}

Then C=cos⁡−1(27)≈73.4∘C = \cos^{-1}\left(\tfrac{2}{7}\right) \approx 73.4^\circ. Keep the fraction exact until the last button press: rounding 27\tfrac{2}{7} to 0.290.29 first would move the answer to about 73.1∘73.1^\circ.

Finding the largest angle first is a deliberate choice. Once it is known, the other two angles must be acute, so there is no sign worry for them. Using the same formula for the angle opposite 77 gives cos⁡A=64+81−492(8)(9)=96144=23\cos A = \dfrac{64 + 81 - 49}{2(8)(9)} = \dfrac{96}{144} = \dfrac{2}{3}, so A≈48.2∘A \approx 48.2^\circ. The third angle is 180∘−73.4∘−48.2∘=58.4∘180^\circ - 73.4^\circ - 48.2^\circ = 58.4^\circ, and you can confirm it directly with cos⁡B=49+81−642(7)(9)=66126≈0.524\cos B = \dfrac{49 + 81 - 64}{2(7)(9)} = \dfrac{66}{126} \approx 0.524, which gives 58.4∘58.4^\circ as well. The last step uses inverse trigonometric functions, and unlike the inverse sine, the inverse cosine never leaves two candidate answers.

Try this: Find the angle opposite the side of length 55 in a 33-44-55 triangle using the formula (you should get 90∘90^\circ). Then change the 55 to 5.55.5 and predict whether the angle rises above or falls below 90∘90^\circ before you calculate.

How does the law of cosines work with obtuse angles?

Suppose a=5a = 5, b=8b = 8 and C=120∘C = 120^\circ. The cosine of 120∘120^\circ is negative: its reference angle is 60∘60^\circ, and in the second quadrant cosine flips sign, so cos⁡120∘=−12\cos 120^\circ = -\tfrac{1}{2} (this value comes straight off the unit circle). Then:

c2=25+64−2(5)(8)(−12)=89+40=129c^2 = 25 + 64 - 2(5)(8)\left(-\tfrac{1}{2}\right) = 89 + 40 = 129

So c=129≈11.36c = \sqrt{129} \approx 11.36. Subtracting a negative number is an addition, which is where hand calculations go wrong: students write 89−4089 - 40 and get 77, which would make c≈7c \approx 7, shorter than a side next to it. An obtuse angle must push its opposite side outward.

You can read the angle type from the sides alone, without a calculator. Compare c2c^2 with a2+b2a^2 + b^2. If c2>a2+b2c^2 > a^2 + b^2, then cos⁡C<0\cos C < 0 and the angle is obtuse; if they are equal, it is a right angle; if c2c^2 is smaller, the angle is acute. In the example above, 129>89129 > 89 confirms the obtuse angle before any trigonometry is done.

Quick check

A triangle has sides 33, 44 and 66. Is its largest angle acute, right or obtuse?

Which special cases of the law of cosines are worth knowing?

At C=90∘C = 90^\circ the cosine is 00, so the formula collapses into c2=a2+b2c^2 = a^2 + b^2. That is the Pythagorean theorem, and it is the reason the correction term is the only new idea. Two other angles give clean shortcuts because their cosines are ±12\pm\tfrac{1}{2}:

C=60∘: c2=a2−ab+b2C=120∘: c2=a2+ab+b2C = 60^\circ:\ c^2 = a^2 - ab + b^2 \qquad C = 120^\circ:\ c^2 = a^2 + ab + b^2

With sides 66 and 88 at 60∘60^\circ, that is 36−48+64=5236 - 48 + 64 = 52 in one line, with no calculator.

The built-in limits

For a real triangle, −1<cos⁡C<1-1 < \cos C < 1, so c2c^2 always lies strictly between (a−b)2(a-b)^2 and (a+b)2(a+b)^2. Equivalently, ∣a−b∣<c<a+b|a-b| < c < a+b.

The edges of that range are the degenerate triangles. At C=180∘C = 180^\circ the sides lie flat in a line and c2=a2+b2+2ab=(a+b)2c^2 = a^2 + b^2 + 2ab = (a+b)^2, so c=a+bc = a + b. At C=0∘C = 0^\circ the sides overlap and c=∣a−b∣c = |a - b|. Any answer outside that interval signals an arithmetic slip.

Law of cosines or law of sines: which one do you use?

Two triangles sharing angle 30 degrees, side 5 and side 8, with third sides 3.93 and 9.93
With A = 30°, a = 5 and b = 8, the quadratic for c has two positive roots, so both triangles exist.

The choice depends on which three pieces of the triangle are given, not on personal preference.

Given Best tool
Two sides and the included angle (SAS) Law of cosines
Three sides (SSS) Law of cosines
Two angles and any side (ASA or AAS) Law of sines
Two sides and a non-included angle (SSA) Law of sines, or cosines with a quadratic

The SSA case deserves care. With A=30∘A = 30^\circ, a=5a = 5 and b=8b = 8, the law of cosines on side aa gives 25=64+c2−2(8)ccos⁡30∘25 = 64 + c^2 - 2(8)c\cos 30^\circ, which simplifies to c2−83 c+39=0c^2 - 8\sqrt{3}\,c + 39 = 0. The discriminant is 192−156=36192 - 156 = 36, so c=43±3c = 4\sqrt{3} \pm 3, about 9.939.93 or 3.933.93. Both are positive, so two different triangles fit the data. Solving the quadratic by the quadratic formula shows the ambiguity openly instead of hiding it inside an inverse sine.

A strong combined strategy for SSS problems: use the law of cosines once for the largest angle, then switch to the law of sines for the rest. Since the remaining angles are guaranteed acute, the sine method cannot mislead you.

How do you check a law of cosines answer?

Four quick tests catch nearly every error:

  1. The third side must satisfy ∣a−b∣<c<a+b|a - b| < c < a + b.
  2. The side opposite the larger angle must be the longer side.
  3. Compare c2c^2 with a2+b2a^2 + b^2: your angle should be acute if c2c^2 is smaller, obtuse if larger.
  4. After finding all three angles, the sum must be 180∘180^\circ (rounding may cause a 0.1∘0.1^\circ gap).

The third test is the sharpest, because it exposes both mode errors and sign errors. If a 35∘35^\circ angle produced a c2c^2 larger than a2+b2a^2 + b^2, the cosine came out negative, and the calculator is almost certainly set to radians.

You can also substitute your answer back in. For the 77-1010-35∘35^\circ example, c≈5.86c \approx 5.86 gives cos⁡C=49+100−34.32140=114.68140≈0.819\cos C = \dfrac{49 + 100 - 34.32}{140} = \dfrac{114.68}{140} \approx 0.819, which matches cos⁡35∘\cos 35^\circ. That round trip takes ten seconds and confirms the arithmetic.

Quick check

Two sides are 77 and 99 with an included angle of 50∘50^\circ. A student gets c=14c = 14. Why is that wrong without a calculator?

Where is the law of cosines used in real life?

Any time two distances and the angle between them are known, the distance between the endpoints follows. Two boats leave the same dock: one travels 1212 km on a bearing of 20∘20^\circ and the other 99 km on a bearing of 95∘95^\circ. The angle between the paths is 95∘−20∘=75∘95^\circ - 20^\circ = 75^\circ, so:

d2=122+92−2(12)(9)cos⁡75∘=225−216(0.2588)≈225−55.9=169.1d^2 = 12^2 + 9^2 - 2(12)(9)\cos 75^\circ = 225 - 216(0.2588) \approx 225 - 55.9 = 169.1

Then d≈13.0d \approx 13.0 km. The same triangle has an area of 12(12)(9)sin⁡75∘≈52.2\tfrac{1}{2}(12)(9)\sin 75^\circ \approx 52.2 km², which follows from the area of a triangle using sine.

Surveyors use the formula to measure across lakes and fields they cannot cross, often combined with angles of elevation and depression to handle slopes. In physics, the resultant of two forces or velocities is a law of cosines problem: the magnitude of u+v\mathbf{u} + \mathbf{v} depends on the angle θ\theta between the vectors through ∣u∣2+∣v∣2+2∣u∣∣v∣cos⁡θ|\mathbf{u}|^2 + |\mathbf{v}|^2 + 2|\mathbf{u}||\mathbf{v}|\cos\theta. Because the triangle’s interior angle is 180∘−θ180^\circ - \theta, the sign flips relative to the formula above.

Practice problems

0 of 5 solved

  1. In a triangle, a=6a = 6, b=8b = 8 and the angle between them is C=60∘C = 60^\circ. Find side cc.

  2. A triangle has sides 55, 77 and 88. Find the angle opposite the side of length 77.

  3. In a triangle, a=9a = 9, b=14b = 14 and the angle between them is C=120∘C = 120^\circ. Find side cc.

  4. A triangle has sides 44, 55 and 66. Find its largest angle.

  5. A parallelogram has sides 66 and 1010 and a long diagonal of 1414. Find the length of the short diagonal.

Common questions

What is the formula for the law of cosines?

For a triangle with sides aa, bb, cc and opposite angles AA, BB, CC, the law is c2=a2+b2−2abcos⁡Cc^2 = a^2 + b^2 - 2ab\cos C. The same pattern works for any side: square the side you want, and use the angle opposite it.

When do you use the law of cosines instead of the law of sines?

Use the law of cosines when you know two sides and the angle between them (SAS) or all three sides (SSS). Use the law of sines when you know a side and its opposite angle plus one more piece of information.

Can the law of cosines be used on a right triangle?

Yes. At C=90∘C = 90^\circ the term cos⁡C\cos C is zero, and the formula becomes the Pythagorean theorem c2=a2+b2c^2 = a^2 + b^2. That is why the law of cosines is called a generalization of Pythagoras.

Why is the law of cosines negative for obtuse angles?

The cosine of an angle between 90∘90^\circ and 180∘180^\circ is negative, so subtracting 2abcos⁡C2ab\cos C actually adds to a2+b2a^2 + b^2. The side opposite an obtuse angle is therefore longer than the hypotenuse of a right triangle with the same two legs.

Does the law of cosines have an ambiguous case?

Not when you solve for an angle, because the inverse cosine returns a single angle between 0∘0^\circ and 180∘180^\circ. Ambiguity appears only in the side-side-angle setup, where solving for the third side gives a quadratic that can have two positive roots.

How do you find an angle with the law of cosines?

Rearrange the formula to cos⁡C=a2+b2−c22ab\cos C = \dfrac{a^2 + b^2 - c^2}{2ab}, substitute all three sides, and apply the inverse cosine. Keep the fraction exact until the last step to avoid rounding errors.

Up next