Uni-Sine
MathematicsTrigonometry

Law of cosines calculator

A law of cosines calculator solves a triangle from two sides and the angle between them (SAS), or from all three sides (SSS). The law of cosines is c² = a² + b² − 2ab cos C. It gives the third side from SAS, and rearranged, it gives any angle from three sides. Type the values into our Trigonometry Calculator and press Solve to get every side and angle.

There is no separate law of cosines mode. The calculator sees that you typed SAS or SSS, uses the law of cosines, and names it in the method line under the buttons.

Try it

Trigonometry Calculator

Interactive triangle solver with step-by-step

Go to its page

How to use the law of cosines calculator

  1. Open the calculator and choose Standard triangle at the top of the sidebar.
  2. Under Triangle, find the panel "Type any three values, including a side, then Solve".
  3. For SAS, type the two sides and the angle between them. The angle between sides a and b is C, between b and c is A, and between a and c is B.
  4. For SSS, type a, b and c and leave the angles empty.
  5. Press Solve. The triangle is redrawn, and Measurements lists every side and angle, the area and the perimeter.

The method line reads "Two sides and the angle between them (SAS): the third side from the cosine rule" or "Three sides (SSS): every angle from the cosine rule". The Formulas section shows the law of cosines for your triangle. The calculator gives the results but not the working, so the examples below show it. If three sides cannot make a triangle, it tells you why.

The law of cosines formula

For a triangle with sides a, b and c opposite angles A, B and C, the law of cosines has three versions, one for each side:

c^2 = a^2 + b^2 - 2ab\cos C
a^2 = b^2 + c^2 - 2bc\cos A
b^2 = a^2 + c^2 - 2ac\cos B

Each one uses the angle between the two sides on the right. To find an angle from three sides, rearrange:

\cos C = \frac{a^2 + b^2 - c^2}{2ab}The law of cosines rearranged for an angle

In the UK it is called the cosine rule, and our cosine rule guide covers the proof and exam questions.

It is Pythagoras with a correction

When C = 90°, cos C = 0, so the last term vanishes and the law of cosines becomes a² + b² = c², the Pythagorean theorem. The −2ab cos C term corrects for the angle not being a right angle. An acute C makes c shorter than Pythagoras would give, and an obtuse C makes it longer, because cos C is negative.

Worked examples you can check in the calculator

Example 1: the third side from SAS

Two boats leave a harbour. One sails 7 km and the other 10 km, along paths 48° apart. How far apart are they? The two paths are sides a and b, and the 48° is the angle C between them:

a = 7c = ?b = 1048°ABC
Angle C sits between the two sides you know, so this is SAS
c^2 = 7^2 + 10^2 - 2 \times 7 \times 10 \times \cos 48° = 55.32
c = \sqrt{55.32} = 7.44\ \text{km}

The boats are 7.44 km apart. Type a = 7, b = 10 and C = 48, then Solve. The calculator also gives the other angles, A = 44.38° and B = 87.62°.

Example 2: an angle from SSS

A triangle has sides 8, 11 and 15. Find its biggest angle. The biggest angle always faces the longest side, so find C, which faces c = 15:

\cos C = \frac{8^2 + 11^2 - 15^2}{2 \times 8 \times 11} = \frac{-40}{176} = -0.2273
C = \cos^{-1}(-0.2273) = 103.14°

A negative cosine means an obtuse angle. Type a = 8, b = 11 and c = 15 with no angles, and the calculator gives C = 103.14°, A = 31.29° and B = 45.57°. Now try one in the course, then press Mark:

Use the cosine rule practice.

Press Mark to have your answer marked in the Trigonometry course.

Example 3: an obtuse angle between the sides

a = 12, c = 9 and the angle between them is B = 120°. Find b. Since cos 120° = −0.5, the last term adds instead of subtracting:

b^2 = 12^2 + 9^2 - 2 \times 12 \times 9 \times \cos 120° = 144 + 81 + 108 = 333
b = \sqrt{333} = 18.25

In the calculator, type a = 12, c = 9 and B = 120. It gives b = 18.25, A = 34.72° and C = 25.28°.

Example 4: sides that cannot make a triangle

Try a = 5, b = 7 and c = 13. The two shorter sides add up to 12, which is less than 13, so they cannot meet. The calculator says "No triangle has these sides: any two must add up to more than the third." Working by hand, you would get cos C below −1, which has no angle.

Law of sines or law of cosines?

Choose by what you are given. The calculator makes this choice for you, but in a test you have to make it yourself.

You knowUseWhy
Two sides and the angle between them (SAS)Law of cosinesNo side has its opposite angle yet
Three sides (SSS)Law of cosinesNo angles at all yet
Two angles and any side (ASA, AAS)Law of sinesYou have, or can quickly get, a side with its opposite angle
Two sides and an angle opposite one of them (SSA)Law of sinesWatch for two possible triangles

After one use of the law of cosines you have a complete side and angle pair, so you can switch to the law of sines for the rest. If you do, find the smaller angle first: the law of sines cannot tell an acute angle from an obtuse one, but the law of cosines can. Our law of sines calculator guide covers the other cases.

Common mistakes

  • Using an angle that is not between the two sides. In c² = a² + b² − 2ab cos C, angle C must be the one where a and b meet.
  • Doing the subtraction too early. Work out 2ab cos C first, then subtract it from a² + b². Typing (49 + 100 − 140) × cos 48° gives the wrong answer.
  • Forgetting the square root. The formula gives c². Take the root at the end.
  • Dropping the minus sign with an obtuse angle. cos 120° is negative, so −2ab cos 120° adds to the total.
  • A calculator in radians. cos 48 in radians is negative. Check for DEG on the screen.
  • Rounding c before finding the angles. Keep the full value of c for the next step.

Practise the law of cosines in a short timed paper

The law of cosines comes up in Geometry, Algebra 2 & SAT Math and AP Precalculus practice, and as the cosine rule in GCSE Maths Higher in the UK. Each daily paper is a short timed paper of 8 questions worth 25 to 35 marks, and the papers mix topics.

Common questions

What is the law of cosines?
A rule linking all three sides of a triangle to one of its angles: c² = a² + b² − 2ab cos C. It works for any triangle, not just right triangles.
When do you use the law of cosines?
When you know two sides and the angle between them (SAS) and want the third side, or when you know all three sides (SSS) and want an angle.
How do you find an angle with the law of cosines?
Rearrange it to cos C = (a² + b² − c²) ÷ 2ab, work out the right-hand side, then take the inverse cosine. A negative result means the angle is obtuse.
Is the law of cosines the same as the Pythagorean theorem?
It includes it. When the angle is 90°, cos 90° = 0 and the law of cosines becomes a² + b² = c².
Can the law of cosines give two answers?
No. Unlike the law of sines, the inverse cosine gives one angle between 0° and 180°, so SAS and SSS triangles have exactly one solution.
Is the law of cosines the same as the cosine rule?
Yes. Law of cosines is the usual US name and cosine rule is the usual UK name.

Revision cards

Say the answer first, then flip the card to check it.

Where to go next

  • Solve it

    Trigonometry Calculator

    Interactive triangle solver with step-by-step

    Open the tool
  • Learn it

    Trigonometry

    Understand the true math behind everyday geometry with trig functions and identities

    Start the course
  • Test it

    Geometry, Algebra 2 & SAT Math

    A new exam-style paper every day, with instant marking and a mark scheme

    Start today's paper
Read next
Maths · TrigonometryLaw of sines calculator: solve triangles, ambiguous caseFree law of sines calculator: solve any triangle from two angles and a side, or two sides and an angle, with both answers in the ambiguous case.