Trigonometry

Law of Cosines

Last updated: March 2026 · Advanced
Before you start

You should be comfortable with:

Real-world applications
📐
Carpentry

Measurements, material estimation, cutting calculations

Electrical

Voltage drop, wire sizing, load balancing

The law of cosines is the generalized Pythagorean theorem. It works for any triangle — not just right triangles — and it handles the cases where the law of sines cannot: when you know two sides and the included angle (SAS), or when you know all three sides (SSS).

The Formula

For any triangle with sides aa, bb, cc opposite angles AA, BB, CC:

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

This looks like the Pythagorean theorem with an extra term. When C=90°C = 90°, cos90°=0\cos 90° = 0, and the formula reduces to c2=a2+b2c^2 = a^2 + b^2 — exactly the Pythagorean theorem.

The formula can be rearranged to solve for any side:

a2=b2+c22bccosAa^2 = b^2 + c^2 - 2bc\cos A

b2=a2+c22accosBb^2 = a^2 + c^2 - 2ac\cos B

To find an angle when all three sides are known, rearrange:

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

Law of Cosines — The Generalized Pythagorean Theorem

CABabcc² = a² + b² − 2ab cos C

When to Use the Law of Cosines

Given InformationCaseWhat You Can Find
Two sides and the included angleSASThe third side
All three sidesSSSAny angle

Memory aid: If you don’t have a matched side-angle pair (a side and the angle directly opposite it), use the law of cosines. If you do have a matched pair, the law of sines is usually simpler.

Common workflow for SSS: Use the law of cosines to find the largest angle first (opposite the longest side), then switch to the law of sines (which is simpler) for the second angle, and subtract to find the third. Finding the largest angle first matters — if the triangle has an obtuse angle, it will always be the largest, and sin1\sin^{-1} on a calculator cannot distinguish obtuse from acute angles (it always returns the acute one).

Worked Examples

Example 1: Finding a Side (SAS)

In triangle ABCABC: a=7a = 7, b=10b = 10, and C=55°C = 55°. Find side cc.

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

c2=72+1022(7)(10)cos55°c^2 = 7^2 + 10^2 - 2(7)(10)\cos 55°

c2=49+100140×0.5736c^2 = 49 + 100 - 140 \times 0.5736

c2=14980.30=68.70c^2 = 149 - 80.30 = 68.70

c=68.70=8.29c = \sqrt{68.70} = 8.29

Answer: c8.29c \approx 8.29

Example 2: Finding an Angle (SSS)

A triangle has sides a=5a = 5, b=8b = 8, and c=10c = 10. Find angle CC (the angle opposite the longest side).

cosC=a2+b2c22ab=25+641002(5)(8)=1180=0.1375\cos C = \frac{a^2 + b^2 - c^2}{2ab} = \frac{25 + 64 - 100}{2(5)(8)} = \frac{-11}{80} = -0.1375

C=cos1(0.1375)=97.90°C = \cos^{-1}(-0.1375) = 97.90°

Answer: C97.90°C \approx 97.90°

This is an obtuse angle, which makes sense — the longest side is always opposite the largest angle.

Example 3: Complete SSS Solution

A triangle has sides 12, 9, and 7. Find all three angles.

Step 1 — Find the largest angle (opposite the longest side, 12):

cosA=92+721222(9)(7)=81+49144126=14126=0.1111\cos A = \frac{9^2 + 7^2 - 12^2}{2(9)(7)} = \frac{81 + 49 - 144}{126} = \frac{-14}{126} = -0.1111

A=cos1(0.1111)=96.38°A = \cos^{-1}(-0.1111) = 96.38°

Step 2 — Use the law of sines to find a second angle (simpler than law of cosines again):

sinB9=sin96.38°12\frac{\sin B}{9} = \frac{\sin 96.38°}{12}

sinB=9×0.993812=0.7454\sin B = \frac{9 \times 0.9938}{12} = 0.7454

B=sin1(0.7454)=48.19°B = \sin^{-1}(0.7454) = 48.19°

Step 3 — Subtract for the third angle:

C=180°96.38°48.19°=35.43°C = 180° - 96.38° - 48.19° = 35.43°

Answer: A96.38°A \approx 96.38°, B48.19°B \approx 48.19°, C35.43°C \approx 35.43°

Verification: The largest angle (96.38°) is opposite the longest side (12) ✓. The smallest angle (35.43°) is opposite the shortest side (7) ✓.

Why the Extra Term Matters

The term 2abcosC-2ab\cos C is what adjusts the Pythagorean theorem for non-right angles:

  • When C=90°C = 90°: cos90°=0\cos 90° = 0, so the term disappears → Pythagorean theorem
  • When C<90°C < 90° (acute): cosC>0\cos C > 0, so you subtract → side cc is shorter than in a right triangle
  • When C>90°C > 90° (obtuse): cosC<0\cos C < 0, so you add → side cc is longer than in a right triangle

This is why a triangle with an obtuse angle has a longer side opposite it.

Real-World Application: Carpentry — Triangular Brace

A carpenter is building a triangular brace. Two beams meet at a 110-degree angle. One beam is 3 feet and the other is 4 feet. How long is the brace that connects their endpoints?

c2=32+422(3)(4)cos110°c^2 = 3^2 + 4^2 - 2(3)(4)\cos 110°

c2=9+1624×(0.3420)=25+8.21=33.21c^2 = 9 + 16 - 24 \times (-0.3420) = 25 + 8.21 = 33.21

c=33.21=5.76 ftc = \sqrt{33.21} = 5.76 \text{ ft}

Answer: The brace is approximately 5.76 feet long.

Notice: if the angle were 90° instead of 110°, the Pythagorean theorem gives 9+16=5\sqrt{9+16} = 5. The obtuse angle pushes the brace length to 5.76 — the law of cosines captures this difference exactly.

Common Mistakes

  1. Forgetting the negative sign. When the angle is obtuse, cosC\cos C is negative, so 2abcosC-2ab\cos C becomes positive (adding to a2+b2a^2 + b^2). Don’t drop the negative.
  2. Using the wrong angle. In c2=a2+b22abcosCc^2 = a^2 + b^2 - 2ab\cos C, angle CC must be the angle between sides aa and bb (the included angle).
  3. Forgetting to take the square root. The formula gives c2c^2, not cc. Remember the final step.
  4. Using the law of cosines when the law of sines is simpler. If you have a matched side-angle pair, the law of sines requires less computation.

Practice Problems

Test your understanding with these problems. Click to reveal each answer.

Problem 1: Two sides of a triangle are 12 and 9, and the angle between them is 40°. Find the third side.

c2=122+922(12)(9)cos40°c^2 = 12^2 + 9^2 - 2(12)(9)\cos 40°

c2=144+81216×0.7660=225165.46=59.54c^2 = 144 + 81 - 216 \times 0.7660 = 225 - 165.46 = 59.54

c=59.54=7.72c = \sqrt{59.54} = 7.72

Answer: The third side is approximately 7.72.

Problem 2: A triangle has sides 6, 8, and 11. Find the largest angle.

The largest angle is opposite the longest side (11). Let c=11c = 11, a=6a = 6, b=8b = 8.

cosC=62+821122(6)(8)=36+6412196=2196=0.2188\cos C = \frac{6^2 + 8^2 - 11^2}{2(6)(8)} = \frac{36 + 64 - 121}{96} = \frac{-21}{96} = -0.2188

C=cos1(0.2188)=102.63°C = \cos^{-1}(-0.2188) = 102.63°

Answer: The largest angle is approximately 102.63°.

Problem 3: An engineer needs a cable from point AA to point CC. She knows AB=50AB = 50 m, BC=35BC = 35 m, and angle B=72°B = 72°. How long is the cable?

AC2=502+3522(50)(35)cos72°AC^2 = 50^2 + 35^2 - 2(50)(35)\cos 72°

AC2=2500+12253500×0.3090=37251081.50=2643.50AC^2 = 2500 + 1225 - 3500 \times 0.3090 = 3725 - 1081.50 = 2643.50

AC=2643.5051.41 mAC = \sqrt{2643.50} \approx 51.41 \text{ m}

Answer: The cable is approximately 51.41 meters long.

Problem 4: A triangle has sides 7, 7, and 10. Find the angle between the two equal sides.

Let a=b=7a = b = 7 and c=10c = 10. Angle CC is between the equal sides.

cosC=72+721022(7)(7)=49+4910098=298=0.0204\cos C = \frac{7^2 + 7^2 - 10^2}{2(7)(7)} = \frac{49 + 49 - 100}{98} = \frac{-2}{98} = -0.0204

C=cos1(0.0204)=91.17°C = \cos^{-1}(-0.0204) = 91.17°

Answer: The angle is approximately 91.17° — just barely obtuse.

Problem 5: Verify: if C=90°C = 90°, show that the law of cosines becomes the Pythagorean theorem.

c2=a2+b22abcos90°c^2 = a^2 + b^2 - 2ab\cos 90°

Since cos90°=0\cos 90° = 0:

c2=a2+b22ab(0)=a2+b2c^2 = a^2 + b^2 - 2ab(0) = a^2 + b^2

This is exactly the Pythagorean theorem: c2=a2+b2c^2 = a^2 + b^2.

Answer: When C=90°C = 90°, the 2abcosC-2ab\cos C term vanishes, reducing the law of cosines to the Pythagorean theorem. ✓

Key Takeaways

  • The law of cosines states c2=a2+b22abcosCc^2 = a^2 + b^2 - 2ab\cos C — it’s the Pythagorean theorem with a correction for non-right angles
  • Use it when you have SAS (two sides + included angle) or SSS (all three sides)
  • When C=90°C = 90°, it reduces to the Pythagorean theorem
  • For SSS: find the largest angle first with law of cosines, then use the law of sines for the second (it’s simpler and safe once the obtuse angle is resolved)
  • An obtuse angle makes cosC\cos C negative, which increases the opposite side length
  • If you have a matched side-angle pair, the law of sines is usually faster

Return to Trigonometry for more topics in this section.

Last updated: March 28, 2026