Law of Cosines Calculator

Third side6.24
Third side squared39.00
Triangle area15.16
How this was calculated
  1. The law of cosines is c^2 = a^2 + b^2 - 2ab cos C: 5^2 + 7^2 - 2 x 5 x 7 x cos(60 degrees) = 39.00.
  2. Take the square root: the square root of 39.00 is 6.24.
  3. The triangle's area is half ab sin C: 0.5 x 5 x 7 x sin(60 degrees) = 15.16.

This law of cosines calculator finds the missing side of a triangle when you know two sides and the angle between them. Enter those three values and it applies c squared = a squared + b squared - 2ab cos C, the generalization of Pythagoras to any triangle. The page reports the third side together with the intermediate steps, so you can follow the arithmetic rather than just accept a number. For example, sides of 5 and 7 with 60 degrees between them give a third side of 6.24, with a third side squared of 39.00 and an area of 15.16. Because the area is half ab sin C, the triangle's area needs the same two sides and the same included angle, so the calculator returns it from the same inputs.

The method is the accepted standard for this kind of calculation because the law of cosines holds for every triangle, not just right-angled ones, and it reduces to familiar results in the cases you already know. Sides of 8 and 10 at a right angle give 12.81 and an area of 40.00: the cosine term vanishes at 90 degrees and Pythagoras returns. Sides of 3 and 4 at 120 degrees give 6.08 and an area of 5.20, showing how an obtuse angle lengthens the opposite side. This page shows the formula, step-by-step workings, worked examples and sources, so you can check each result against the inputs you entered.

Worked examples

60 degree included angle

Sides of 5 and 7 with 60 degrees between them give a third side of 6.24 and an area of 15.16. (5 · 7 · 60 deg)

Third side6.24
Third side squared39.00
Triangle area15.16

Right angle

Sides of 8 and 10 at a right angle give 12.81 and an area of 40.00. (8 · 10 · 90 deg)

Third side12.81
Third side squared164.00
Triangle area40.00

Obtuse 120 degrees

Sides of 3 and 4 at 120 degrees give 6.08 and an area of 5.20. (3 · 4 · 120 deg)

Third side6.08
Third side squared37.00
Triangle area5.20

What the law of cosines is

The law of cosines is the rule c squared = a squared + b squared - 2ab cos C. It is the generalization of Pythagoras to any triangle, not just right triangles. In a right triangle the Pythagorean theorem tells you the third side from the other two. The law of cosines does the same job but also accounts for the angle between those two sides, so it works whether that angle is acute, right, or obtuse. A law of cosines calculator takes the two known sides and the included angle and returns the third side, along with the intermediate values that show how the result was reached.

The easiest way to read the formula is as Pythagoras with a correction term. Start with a squared + b squared, the familiar sum of squares. Then subtract 2ab cos C. That correction is the only new piece, and its size and sign depend entirely on the angle C between the two known sides. When C is a right angle, cos C is zero, so the whole correction term vanishes and the formula collapses back to the Pythagorean theorem. When C is obtuse, cos C is negative, so subtracting it makes the correction positive and the opposite side comes out longer than Pythagoras alone would predict.

The worked examples make the correction term concrete. Take sides of 5 and 7 with 60 degrees between them. The third side is 6.24, its square is 39.00, and the triangle's area is 15.16. Now take sides of 8 and 10 at a right angle. The third side is 12.81 and the area is 40.00; because the cosine term vanishes at 90 degrees, Pythagoras returns. Finally, take sides of 3 and 4 at 120 degrees. The third side is 6.08 and the area is 5.20. The obtuse angle lengthens the opposite side, which is exactly the effect the negative cosine produces in the formula.

The area figures come from a companion rule: the triangle area is half ab sin C. Notice that it needs the same two sides and the same included angle as the law of cosines. That is why a calculator built around the cosine rule can report area alongside the missing side without asking for anything extra. The two formulas share their inputs, so one set of side lengths and one angle is enough to describe the triangle completely.

In practice, you reach for the law of cosines when you know two sides and the angle between them, or when you know all three sides and want an angle. The formula above solves the first case directly. For the second, the same relationship is rearranged to isolate the cosine of the angle. Either way, the correction term is what separates the general triangle from the special right-triangle case.

At 90 degrees the correction term is zero and the law of cosines becomes the Pythagorean theorem; at obtuse angles it is negative, so subtracting it lengthens the opposite side.

How it is calculated

The law of cosines is c squared = a squared + b squared - 2ab cos C, the generalisation of Pythagoras to any triangle. That single line tells you exactly what a law of cosines calculator does: it takes the two sides you know and the angle between them, squares both sides, subtracts twice their product times the cosine of the included angle, and then takes the square root of the result. The square root step is what turns the squared third side back into a plain length. Nothing else is needed — no triangle has to be drawn, and no right angle is required.

Take sides of 5 and 7 with 60 degrees between them. Square both sides and add: 25 plus 49 is 74. Twice their product is 70, and the cosine of 60 degrees is 0.5, so the term to subtract is 35. That leaves a third side squared of 39.00, and the square root gives a third side of 6.24. The same two sides and the same included angle also fix the area, because area is half ab sin C; here that works out to 15.16.

Now try sides of 8 and 10 at a right angle. Squaring and adding gives 64 plus 100, or 164. The cosine of 90 degrees is zero, so the subtraction term vanishes entirely and Pythagoras returns: the square root of 164 is 12.81. The area is half of 8 times 10, which is 40.00. This is the case where the general rule quietly collapses into the familiar right-triangle rule, and it is a useful check that the calculator is behaving.

Finally, sides of 3 and 4 at 120 degrees. Squaring and adding gives 9 plus 16, or 25. Twice the product is 24, and the cosine of 120 degrees is negative, so subtracting that term adds to the total rather than reducing it. The result is a third side of 6.08 — an obtuse angle lengthens the opposite side, pushing it beyond what Pythagoras would predict. The area, half of 3 times 4 times the sine of 120 degrees, comes to 5.20.

Notice the pattern across all three examples. The two known sides and the included angle are the only inputs; everything else follows from them. The cosine term is positive and subtracts for acute angles, zero at 90 degrees, and negative — so it adds — for obtuse angles. The area uses the same two sides and the same included angle, with sine in place of cosine.

Same two sides, same included angle: square both, subtract twice their product times the cosine of the angle, then take the square root.

Area from the same inputs

The law of cosines calculator already has everything it needs to find the area of a triangle, because the area formula uses the same two sides and the same included angle. The area is half ab sin C. Notice what is missing from that expression: the third side. You do not need to solve for c first, and you do not need the other two angles. Once you know two sides and the angle between them, the area is a single step away.

Working through the same three examples shows how this plays out. With sides of 5 and 7 and 60 degrees between them, the third side comes out to 6.24, with a third side squared of 39.00, and the area is 15.16. The cosine term is doing real work here, changing the third side away from what Pythagoras alone would predict, but the area calculation ignores it entirely. Only the two given sides and the 60-degree angle matter.

The right-angle case is the cleanest illustration. Sides of 8 and 10 at a right angle give a third side of 12.81 and an area of 40.00. At 90 degrees the cosine term vanishes, and Pythagoras returns as a special case of the law of cosines. The area is simply half of 8 times 10, which is 40.00, exactly as expected for a right triangle with those legs.

The obtuse case shows the opposite effect. Sides of 3 and 4 at 120 degrees give 6.08, and an obtuse angle lengthens the opposite side beyond what a right angle would produce. The area, though, is 5.20. That number is smaller than the right-angle result for comparable sides, which makes sense: as the included angle opens past 90 degrees, the sine of the angle begins to fall, and the area shrinks with it. The same two sides and the same included angle drive both calculations, so the area is never more than a step behind the third side.

If you are using a law of cosines calculator to find a missing side, the area is a useful check on your inputs. Enter the two sides and the included angle, confirm the third side, and then confirm the area from the same numbers. If either result looks off, the inputs are the likely culprit, not the formulas.

Area = half ab sin C. The third side is optional.

When to use it

Reach for a law of cosines calculator when you know two sides of a triangle and the angle between them, or when you know all three sides and want the angles. In the first case, the two known sides meet at a vertex, and the angle between them is called the included angle. That combination is often written as SAS, for side-angle-side, and it is the most natural fit for the law of cosines, c squared = a squared + b squared - 2ab cos C. The formula is the generalization of Pythagoras to any triangle, which is why it handles what the Pythagorean theorem alone cannot.

A quick example shows the pattern. Suppose two sides measure 5 and 7 with 60 degrees between them. The third side comes out to 6.24, the third side squared is 39.00, and the area is 15.16. The same tool covers right triangles too: sides of 8 and 10 at a right angle give 12.81 and an area of 40.00. At 90 degrees the cosine term vanishes and Pythagoras returns, so the law of cosines agrees with the familiar rule rather than replacing it. Obtuse included angles behave as you would expect: sides of 3 and 4 at 120 degrees give 6.08 and an area of 5.20, because an obtuse angle lengthens the opposite side.

The second main use is running the relationship backwards. When you know all three sides and none of the angles, often called SSS, you cannot start with the law of sines, because it needs at least one known angle to work from. The law of cosines lets you solve for an angle directly from the three sides, then repeat for a second angle, after which the third follows from the fact that a triangle's angles add up. This is the standard route for side-side-side triangles solved backwards for angles.

The law of sines is the better tool once you already have a side paired with its opposite angle, the arrangement labeled AAS or ASA, or when you have two sides and a non-included angle, SSA. In those setups the law of sines is shorter and involves fewer steps. The dividing line is simple: if the angle you know sits between the two sides you know, or if you know all three sides and no angles, use the law of cosines. If a known side faces a known angle, the law of sines usually gets you there faster.

One more pairing is worth remembering. The triangle area is half ab sin C, so it needs the same two sides and the same included angle as the law of cosines. That means an SAS problem gives you both the missing side and the area from the same starting facts, which is why the two formulas so often appear together in the same calculation.

  • SAS: two sides and the included angle are known — solve for the third side with the law of cosines.
  • SSS: all three sides are known and no angle is — solve backwards for the angles.
  • Right triangles: the cosine term vanishes at 90 degrees and the result matches Pythagoras.
  • AAS, ASA or SSA: a known side faces a known angle — the law of sines is usually the shorter route.
  • Area: half ab sin C uses the same two sides and included angle, so SAS problems yield side and area together.
Rule of thumb: if the angle sits between the two known sides, or you know all three sides, use the law of cosines. If a known side faces a known angle, the law of sines is usually quicker.

FAQs

What is the law of cosines?

The law of cosines states that c squared = a squared + b squared - 2ab cos C. It lets you find the third side of a triangle from two known sides and the angle between them. The formula works for any triangle, not just right triangles, which makes it a general tool for solving side lengths.

How do you find the third side?

Square both known sides, subtract 2ab cos C, then take the square root of the result. For example, with sides 5 and 7 and an included angle of 60 degrees, the calculation gives a third side of 6.24. The order matters: compute the subtraction before taking the root.

What happens at 90 degrees?

At 90 degrees, cosine is zero, so the correction term vanishes and the law reduces to Pythagoras. With sides 8 and 10 at a right angle, the opposite side is 12.81. This shows the Pythagorean theorem is simply the special case of the law of cosines for right triangles.

What happens at an obtuse angle?

When the angle is obtuse, cosine goes negative, so subtracting a negative adds the correction term and the opposite side lengthens. With sides 3 and 4 at 120 degrees, the opposite side comes out to 6.08. The negative cosine is what makes the side longer than it would be at a right angle.

How do you find the area with the law of cosines?

Once you have the needed sides and the included angle, use half ab sin C. With sides 5 and 7 at 60 degrees, the area is 15.16. The law of cosines supplies the missing side or angle from your inputs, and the area formula then uses the same angle and two sides.

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

Use the law of cosines whenever the triangle is not right-angled. Pythagoras is only the special case where the included angle is 90 degrees. For any other angle, the cosine correction term is nonzero, so you need the full law of cosines to get the correct side length.

Sources

Related calculators

Heron's Formula Calculator
The area of any triangle from its three sides alone — plus the semiperimeter, inradius and circumradius.
Right Triangle Calculator
Solve a right triangle from two legs, a leg and the hypotenuse, or a leg and its opposite angle — hypotenuse, angles, area and perimeter.
Bearing Angle Calculator
The initial great-circle bearing from one latitude and longitude to another, with the back bearing for the return leg.