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

Law of Cosines Calculator

Solve a triangle from two sides and the included angle, or from all three sides, and get the missing side, every angle and the area with each step of the law of cosines shown.

Examples

About the Law of Cosines Calculator

Right-angled triangles can be solved with the Pythagorean theorem and basic trigonometry, but most triangles in surveying, navigation, engineering and physics have no right angle. The law of cosines extends Pythagoras to every triangle, and it is the tool to reach for when you know two sides and the angle between them, or all three sides and no angles.

This calculator handles both cases. In SAS mode it finds the third side, keeping an exact radical such as 39\sqrt{39} when one exists, then the two remaining angles. In SSS mode it checks that the sides can form a triangle and finds all three angles. In both modes it finishes with the area.

What is the law of cosines?

In a triangle with sides aa, bb and cc opposite angles AA, BB and CC, the law of cosines states c2=a2+b2−2abcos⁡Cc^2 = a^2 + b^2 - 2ab\cos C. The same relationship holds for each side with its opposite angle.

When C=90°C = 90°, cos⁡C=0\cos C = 0 and the formula reduces to c2=a2+b2c^2 = a^2 + b^2, the Pythagorean theorem. The extra term −2abcos⁡C-2ab\cos C corrects for the angle: it shrinks cc when CC is acute and lengthens it when CC is obtuse, because the cosine of an obtuse angle is negative.

How to use the Law of Cosines Calculator

  1. Choose SAS (two sides and the included angle) or SSS (three sides).
  2. Enter sides aa and bb.
  3. In SAS mode, enter the included angle CC in degrees; in SSS mode, enter the third side cc.
  4. Press Solve triangle to see the missing side or angles, then the area.
  5. Check the result: the angles should add to 180° and the largest angle should face the longest side.

Formulas

Law of cosines

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

Solved for an angle

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

Angle sum

A+B+C=180∘A + B + C = 180^\circ

Area (SAS)

K=12absin⁡CK = \tfrac12 ab\sin C

Worked example: a = 5, b = 7, C = 60°

The example has a=5a = 5, b=7b = 7 and an included angle C=60°C = 60°. Since cos⁡60°=12\cos 60° = \frac12, the formula gives c2=25+49−35=39c^2 = 25 + 49 - 35 = 39, so c=39≈6.245c = \sqrt{39} \approx 6.245.

The engine then finds angle AA from the rearranged law of cosines, about 43.898°43.898°, and angle BB from the angle sum, about 76.102°76.102°. The area is 12⋅5⋅7⋅sin⁡60°=3534≈15.155\frac12 \cdot 5 \cdot 7 \cdot \sin 60° = \frac{35\sqrt3}{4} \approx 15.155.

The solution below is generated by the same engine that powers the calculator above.

Final answer

c = √39 ≈ 6.244997998; A ≈ 43.897886°, B ≈ 76.102114°

How we read your problem

SAS: find the third side and the remaining angles

Step-by-step solution

  1. Substitute into c² = a² + b² − 2ab·cos C

    c2=52+72−2(5)(7)cos⁡60∘=39c^2 = 5^2 + 7^2 - 2(5)(7)\cos 60^\circ = 39
  2. Take the square root

    c=39=39≈6.244997998c = \sqrt{39} = \sqrt{39} \approx 6.244997998
  3. Find angle A with the law of cosines rearranged

    cos⁡A=b2+c2−a22bc≈0.72057669⇒A≈43.897886∘\cos A = \frac{b^2 + c^2 - a^2}{2bc} \approx 0.72057669 \Rightarrow A \approx 43.897886^\circ
  4. Angles of a triangle add to 180°

    B=180∘−A−C≈76.102114∘B = 180^\circ - A - C \approx 76.102114^\circ
  5. Area from two sides and the included angle

    Area=12absin⁡C≈15.155445\text{Area} = \tfrac12ab\sin C \approx 15.155445

Formulas used

  • Law of cosines

    c2=a2+b2−2abcos⁡Cc^2 = a^2 + b^2 - 2ab\cos C
  • Solved for an angle

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

    Area=12absin⁡C\text{Area} = \tfrac12 ab\sin C

The triangle has sides a = 5, b = 7, c ≈ 6.244998 and angles A ≈ 43.897886°, B ≈ 76.102114°, C ≈ 60°. It is an acute scalene triangle with area ≈ 15.155445 and perimeter ≈ 18.244998.

Verification

  • A + B + C = 180°.
  • Heron's formula gives the same area: 15.155445.
  • Law of sines ratios: a/sin A ≈ 7.2111026, b/sin B ≈ 7.2111026, c/sin C ≈ 7.2111026.

Detailed explanation

Solving SAS triangles

With two sides and the angle between them, the law of cosines gives the third side directly. Only one triangle is possible, so there is no ambiguity. With all three sides known, the rearranged formula gives each angle in turn. The calculator uses the law of cosines rather than the law of sines for the second angle because the cosine formula cannot confuse an acute angle with its obtuse supplement.

Obtuse included angles work the same way. For a=4a = 4, b=6b = 6 and C=120°C = 120°, cos⁡120°=−12\cos 120° = -\frac12, so c2=16+36+24=76c^2 = 16 + 36 + 24 = 76 and c=219≈8.718c = 2\sqrt{19} \approx 8.718, longer than either given side as expected.

Solving SSS triangles

Three lengths form a triangle only if each pair adds to more than the third, the triangle inequality. The calculator checks this first: sides 1, 2 and 5 are rejected because 1+2<51 + 2 < 5. For valid sides it computes angle CC, then angle AA, both from the rearranged formula, and finds BB from the angle sum. Enter the longest side as cc and the first angle found tells you whether the triangle is acute, right or obtuse: sides 3, 4 and 5 give C=90°C = 90°.

Law of cosines or law of sines?

Use the law of cosines for SAS and SSS, where no side-angle pair is known. Use the law of sines for ASA, AAS and SSA, where at least one side is known together with its opposite angle. The SSA case can have two solutions; the law of cosines cases never do, which makes them the more reliable starting point when you have a choice.

Common mistakes

  • Using an angle that is not between the two given sides in SAS mode.
  • Forgetting the factor of 2 in 2abcos⁡C2ab\cos C.
  • Leaving a calculator in radian mode when the angle is in degrees.
  • Subtracting 2ab2ab before multiplying by cos⁡C\cos C, which breaks the order of operations.
  • Skipping the triangle inequality check and getting an impossible cosine greater than 1.

Tips

  • Label the triangle so the unknown side is cc and the known angle is CC.
  • The largest angle is always opposite the longest side; use this to check your answer.
  • Keep exact values such as 39\sqrt{39} until the final step to avoid rounding drift.
  • Use the unit circle calculator to recall exact cosines of special angles.
  • For right triangles, the distance formula and Pythagoras are quicker.

Frequently asked questions

When should I use the law of cosines?

When you know two sides and the included angle (SAS) or all three sides (SSS). In these cases no side is known with its opposite angle, so the law of sines cannot start.

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

Rearrange it to cos C = (a² + b² − c²) / (2ab), substitute the three sides and take the inverse cosine.

How is the law of cosines related to the Pythagorean theorem?

When the angle C is 90°, cos C is 0 and the formula becomes c² = a² + b². The law of cosines is the general version for any triangle.

What if my three sides do not form a triangle?

The calculator checks the triangle inequality and reports an error if one side is at least as long as the other two combined, as with sides 1, 2 and 5.

Are the triangle results exact or rounded?

When the third side is a square root it is shown exactly, such as √39 or 2√19, together with a decimal. Angles are given in decimal degrees.

How is the area calculated?

With the formula area = ½ab sin C, using two sides and the angle between them. In SSS mode the angle is found first.

Can the law of cosines give two triangles?

No. SAS and SSS data always determine a single triangle. The ambiguous case with two possible triangles only arises with SSA data and the law of sines.

Solve your triangle

Enter two sides and an angle, or three sides, above to find every missing measurement and the area.

More math calculators