Skip to content
  • Open the math solver
  • Ask the AI tutor
  • Find an AP course
  • Create a quiz
  • Open the calculator
  • Graphing Calculator
  • Browse all calculators
  • Read math guides
↑ ↓Enter to open · Esc to close
Solve a problem

Trigonometry

The Law of Cosines Explained with Examples

By MathSolver Pro Editorial Team · Published

The law of cosines extends the Pythagorean theorem to every triangle. It finds the third side when you know two sides and the angle between them, and it finds any angle when you know all three sides.

The formula

Label the triangle in the usual way: angles AA, BB, CC, with sides aa, bb, cc opposite them. The law of cosines has three versions, one for each side, and they all follow the same pattern:

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

Read it as: the square of one side equals the sum of the squares of the other two, minus a correction term. The angle in the correction term is the one opposite the side on the left, which is also the angle between the two sides on the right. When C=90∘C = 90^\circ, cos⁡C=0\cos C = 0 and the correction vanishes, leaving c2=a2+b2c^2 = a^2 + b^2. So the Pythagorean theorem is a special case.

Solving for the cosine gives the form used to find angles:

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

A short proof with coordinates

Place vertex CC at the origin and side aa along the positive x-axis, so vertex BB is at (a,0)(a, 0). Vertex AA is at distance bb from the origin in the direction of angle CC, so its coordinates are (bcos⁡C,bsin⁡C)(b\cos C, b\sin C).

Side cc is the distance from AA to BB. By the distance formula, c2=(bcos⁡C−a)2+(bsin⁡C)2c^2 = (b\cos C - a)^2 + (b\sin C)^2. Expanding gives b2cos⁡2C−2abcos⁡C+a2+b2sin⁡2Cb^2\cos^2 C - 2ab\cos C + a^2 + b^2\sin^2 C, and since cos⁡2C+sin⁡2C=1\cos^2 C + \sin^2 C = 1, this is a2+b2−2abcos⁡Ca^2 + b^2 - 2ab\cos C. The proof works whether CC is acute or obtuse, because the coordinates handle the signs automatically.

The same identity appears in vector form as ∣u−v∣2=∣u∣2+∣v∣2−2 u⋅v|\mathbf{u} - \mathbf{v}|^2 = |\mathbf{u}|^2 + |\mathbf{v}|^2 - 2\,\mathbf{u}\cdot\mathbf{v}, which is why the dot product can be used to find the angle between vectors.

Finding a side: two sides and the included angle

When you know two sides and the angle between them (SAS), the law of sines cannot start, because no side is paired with its opposite angle. The law of cosines gives the third side directly.

Example 1: a=7a = 7, b=9b = 9, C=48∘C = 48^\circ

  1. Substitute: c2=72+92−2(7)(9)cos⁡48∘=130−126cos⁡48∘c^2 = 7^2 + 9^2 - 2(7)(9)\cos 48^\circ = 130 - 126\cos 48^\circ.
  2. cos⁡48∘≈0.6691\cos 48^\circ \approx 0.6691, so c2≈130−84.31=45.69c^2 \approx 130 - 84.31 = 45.69 and c≈6.76c \approx 6.76.
  3. Find the angle opposite the longest given side, b=9b = 9, with the law of cosines again: cos⁡B=72+6.762−922(7)(6.76)\cos B = \frac{7^2 + 6.76^2 - 9^2}{2(7)(6.76)}, giving B≈81.68∘B \approx 81.68^\circ.
  4. The last angle: A=180∘−48∘−81.68∘≈50.32∘A = 180^\circ - 48^\circ - 81.68^\circ \approx 50.32^\circ.

Example 2: two hikers

  1. Two hikers leave a camp along straight paths that are 60∘60^\circ apart. One walks 5 km and the other 8 km. How far apart are they?
  2. d2=52+82−2(5)(8)cos⁡60∘=25+64−40=49d^2 = 5^2 + 8^2 - 2(5)(8)\cos 60^\circ = 25 + 64 - 40 = 49.
  3. d=7d = 7 km exactly, because cos⁡60∘=12\cos 60^\circ = \frac{1}{2}.

Finding angles: three sides

With all three sides known (SSS), use the cosine form for each angle. Start with the largest angle, the one opposite the longest side. If it is obtuse, its cosine is negative, and the inverse cosine handles that correctly because it returns angles from 0∘0^\circ to 180∘180^\circ. Once the largest angle is known, the other two must be acute, so even the law of sines could finish without any ambiguity.

Example 3: a=5a = 5, b=7b = 7, c=10c = 10

  1. Largest angle CC: cos⁡C=25+49−1002(5)(7)=−2670≈−0.3714\cos C = \frac{25 + 49 - 100}{2(5)(7)} = \frac{-26}{70} \approx -0.3714, so C≈111.80∘C \approx 111.80^\circ, an obtuse angle.
  2. Angle AA: cos⁡A=49+100−252(7)(10)=124140≈0.8857\cos A = \frac{49 + 100 - 25}{2(7)(10)} = \frac{124}{140} \approx 0.8857, so A≈27.66∘A \approx 27.66^\circ.
  3. Angle BB: 180∘−111.80∘−27.66∘≈40.54∘180^\circ - 111.80^\circ - 27.66^\circ \approx 40.54^\circ. Computing it directly, cos⁡B=25+100−49100=0.76\cos B = \frac{25 + 100 - 49}{100} = 0.76, gives the same value.

If the three lengths cannot form a triangle, the formula tells you: the cosine comes out outside [−1,1][-1, 1]. For sides 3, 4 and 8, the angle opposite 8 has cos⁡=9+16−6424=−1.625\cos = \frac{9 + 16 - 64}{24} = -1.625, which is impossible, matching the triangle inequality 3+4<83 + 4 < 8.

Acute, right or obtuse without a calculator

The sign of a2+b2−c2a^2 + b^2 - c^2 matches the sign of cos⁡C\cos C. With cc the longest side, that gives a quick classification:

  • c2<a2+b2c^2 < a^2 + b^2: the largest angle is acute, so the triangle is acute.
  • c2=a2+b2c^2 = a^2 + b^2: the triangle is right angled.
  • c2>a2+b2c^2 > a^2 + b^2: the triangle is obtuse.

For sides 5, 7 and 10, 100>74100 > 74, so the triangle is obtuse, as Example 3 confirmed. For 6, 8 and 9, 81<10081 < 100, so it is acute.

Area from three sides: Heron's formula

Combining the law of cosines with the area formula 12absin⁡C\frac{1}{2}ab\sin C leads to Heron's formula, which needs only the side lengths. Let s=a+b+c2s = \frac{a + b + c}{2} be the semi-perimeter. Then:

Area=s(s−a)(s−b)(s−c)\text{Area} = \sqrt{s(s - a)(s - b)(s - c)}

For sides 5, 7 and 10, s=11s = 11 and the area is 11⋅6⋅4⋅1=264≈16.25\sqrt{11 \cdot 6 \cdot 4 \cdot 1} = \sqrt{264} \approx 16.25. As a check, 12(5)(7)sin⁡111.80∘\frac{1}{2}(5)(7)\sin 111.80^\circ gives the same 16.25.

Choosing between the laws

Use the law of cosines for SAS and SSS, the two cases with no side and opposite angle pair. Use the law of sines when you have a side with its opposite angle. In mixed problems, the law of cosines often comes first and the law of sines finishes. The solving triangles guide sets out every case in one place.

One practical advantage of the law of cosines is that it never produces an ambiguous answer for an angle, because each cosine between −1-1 and 1 corresponds to exactly one angle between 0∘0^\circ and 180∘180^\circ. The law of sines, by contrast, cannot tell an acute angle from its obtuse supplement. That is why many textbooks recommend finding the largest angle with cosines whenever an obtuse angle is possible.

Common mistakes

  • Computing a2+b2−2aba^2 + b^2 - 2ab first and then multiplying by cos⁡C\cos C. The multiplication 2abcos⁡C2ab\cos C must happen before the subtraction.
  • Using an angle that is not between the two given sides.
  • Forgetting to take the square root at the end when finding a side.
  • Mixing degrees and radians on the calculator.
  • Rounding cc early and then using the rounded value to find the angles.

The law of cosines calculator solves SAS, SSS and other cases with each substitution shown. To review the exact values of cosine at special angles, see the unit circle calculator.

Where the law of cosines is used

Any situation with two known distances and the angle between them is a law of cosines problem. Navigators use it to find how far a ship is from port after two legs of a journey on different headings. Engineers use it to find the length of a brace or cable that joins the ends of two beams meeting at a known angle. In robotics, the angle each joint of a two link arm must take to reach a point is found by solving the law of cosines for an angle, because the lengths of the two links and the distance to the target are all known.

The same formula measures how similar two lists of numbers are in data science. Treating each list as a vector, the cosine of the angle between them, computed from the dot product, is called cosine similarity, and it is used in search engines and recommendation systems. The geometry is identical to the triangle version; only the number of dimensions changes.

Practice problems with answers

  1. Sides 4 and 6 meet at 120∘120^\circ. Find the third side. Answer: 16+36+24=76≈8.72\sqrt{16 + 36 + 24} = \sqrt{76} \approx 8.72, since cos⁡120∘=−12\cos 120^\circ = -\frac{1}{2}.
  2. Find the largest angle of the triangle with sides 7, 8 and 13. Answer: cos⁡C=49+64−169112=−12\cos C = \frac{49 + 64 - 169}{112} = -\frac{1}{2}, so the angle is exactly 120∘120^\circ.
  3. Is the triangle with sides 9, 12 and 15 acute, right or obtuse? Answer: 81+144=225=15281 + 144 = 225 = 15^2, so it is a right triangle.
  4. Find the area of the triangle with sides 13, 14 and 15. Answer: s=21s = 21, area =21⋅8⋅7⋅6=84= \sqrt{21 \cdot 8 \cdot 7 \cdot 6} = 84.

Frequently asked questions

Is the law of cosines the same as the Pythagorean theorem?

It is a generalisation. For a right angle, cos⁡90∘=0\cos 90^\circ = 0, so the extra term disappears and the law becomes c2=a2+b2c^2 = a^2 + b^2. For other angles, the term −2abcos⁡C-2ab\cos C corrects for how far the angle is from a right angle.

What happens to the formula when the angle is obtuse?

The cosine of an obtuse angle is negative, so −2abcos⁡C-2ab\cos C becomes positive and the opposite side is longer than the Pythagorean value. That matches intuition: opening the angle wider pushes the ends further apart.

Which angle should I find first in an SSS problem?

Find the angle opposite the longest side first. It is the only one that could be obtuse, and the inverse cosine identifies it correctly. The remaining two angles are then guaranteed to be acute.

Can the law of cosines detect impossible triangles?

Yes. If three lengths break the triangle inequality, the cosine formula gives a value below −1-1 or above 1, which no angle has. Sides 3, 4 and 8 give −1.625-1.625, for example.

Do I need degrees or radians for the law of cosines?

Either works, as long as your calculator is set to the same unit as the angle you type in. Most triangle problems give angles in degrees, so check that the calculator is in degree mode before evaluating cos⁡C\cos C.

MathSolver Pro Editorial Team

Math content and review

Our editorial team writes every guide to explain the reasoning behind each method, not just the answer. Each worked example is checked against the site's own solver engines and automated tests before it is published, and articles are revised whenever a method or an exam format changes.