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.
Trigonometry Calculator
Interactive triangle solver with step-by-step
How to use the law of cosines calculator
- Open the calculator and choose Standard triangle at the top of the sidebar.
- Under Triangle, find the panel "Type any three values, including a side, then Solve".
- 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.
- For SSS, type a, b and c and leave the angles empty.
- 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:
Each one uses the angle between the two sides on the right. To find an angle from three sides, rearrange:
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:
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:
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:
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 know | Use | Why |
|---|---|---|
| Two sides and the angle between them (SAS) | Law of cosines | No side has its opposite angle yet |
| Three sides (SSS) | Law of cosines | No angles at all yet |
| Two angles and any side (ASA, AAS) | Law of sines | You have, or can quickly get, a side with its opposite angle |
| Two sides and an angle opposite one of them (SSA) | Law of sines | Watch 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?
When do you use the law of cosines?
How do you find an angle with the law of cosines?
Is the law of cosines the same as the Pythagorean theorem?
Can the law of cosines give two answers?
Is the law of cosines the same as the cosine rule?
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