Lelifi·tools

Law of Cosines Calculator

The angle opposite the 10 in a 7, 8, 10 triangle is 83.33 degrees. Cos C comes out at (49 + 64 - 100) / 112 = 0.1161, and the inverse cosine of that is 83.33 degrees.

Enter three sides, or two sides and the angle between them, and get the missing side and angles, the area, and whether the triangle is acute, right or obtuse.

By the Lelifi editors ·

Key takeaways

The angle opposite the longest sideSides 7, 8, 1083.33 degSides 3, 4, 590.00 degSides 5, 6, 9109.47 degSides 4, 5, 8125.10 degOne law covers all four: acute, right and obtuse fall out of the same cosine.
The same rule returns an acute, a right and an obtuse angle depending on the sides.
Side c as the included angle opens, with a = 5 and b = 630 degrees3.0140 degrees3.8860 degrees5.5790 degrees7.81120 degrees9.54150 degrees10.63c^2 = 25 + 36 - 60 cos C, so the side grows fastest as the angle passes 90 degrees.
Side c for a = 5 and b = 6 as the included angle widens from 30 to 150 degrees.
On this page
  1. The rule, and which side sits opposite which angle
  2. Two sides and the angle between them (SAS)
  3. Three sides and every angle (SSS)
  4. The angle form, and what the sign tells you
  5. Area from the same two sides
  6. When it beats the law of sines
  7. Where the rule shows up in the field

The rule, and which side sits opposite which angle

The law of cosines ties the three sides of any triangle to the cosine of one of its angles: c^2 = a^2 + b^2 - 2ab cos C. C is the angle between sides a and b, and c is the side opposite it. The letters pair up throughout, with side a facing angle A and side b facing angle B.

Two properties make the rule worth carrying. It holds for every triangle, not only right angled ones, and at C = 90 degrees the cosine term disappears, leaving a^2 + b^2 = c^2. The Pythagorean theorem is the special case, not a separate rule. OpenStax Algebra and Trigonometry, section 10.2 derives the general form from the distance formula, which is the shortest proof to keep in mind.

Rearranged, the same equation returns an angle from three sides: cos C = (a^2 + b^2 - c^2) / (2ab). One rule, two directions, and between them they cover every triangle that can be solved from sides alone.

To findFormulaWhat you must know
Third side cc^2 = a^2 + b^2 - 2ab cos Ca, b and the angle between them
Angle Ccos C = (a^2 + b^2 - c^2) / (2ab)all three sides
Side aa^2 = b^2 + c^2 - 2bc cos Ab, c and the angle between them

The rule is the dot product in disguise. Take two vectors of lengths a and b with angle C between them; the length of their difference is c, and expanding the square of a minus b gives a^2 + b^2 - 2ab cos C. That is why the same expression turns up in physics for work, in statistics for covariance, and in graphics for the angle between two normals.

Two sides and the angle between them (SAS)

Start with a = 5, b = 6 and C = 40 degrees. The cosine of 40 is 0.7660, so c^2 = 25 + 36 - 2 x 5 x 6 x 0.7660 = 61 - 45.96 = 15.04, which gives c = 3.88.

The other angles come from the same rule, run once more with the new side in place. cos A = (36 + 15.04 - 25) / (2 x 6 x 3.88) = 0.5595, so A = 55.98 degrees, and B = 180 - 40 - 55.98 = 84.02 degrees. The area is 0.5 x 5 x 6 x sin 40 = 9.64 square units, and the perimeter is 14.88.

Order matters for accuracy. Start with the largest angle, the one opposite the longest side, and take the smaller two from the sine rule. The inverse cosine is steepest near 1 and -1, so an angle close to 0 or 180 degrees magnifies a small rounding error in the sides, while angles near 90 degrees are the calmest. Here c is the shortest side, so C is the smallest angle and the most exposed to that effect.

abAngle CSide cArea
5640 degrees3.889.64
81135 degrees6.3925.24
129110 degrees17.2950.74
7760 degrees7.0021.22

Oblique triangles are the normal case in this work. A right triangle has a hypotenuse and two legs; an oblique triangle has neither, so the Pythagorean theorem cannot start and the cosine rule carries the whole job. Isosceles and scalene shapes are both covered, because nothing in the formula assumes two sides are equal.

Three sides and every angle (SSS)

With all three sides, the law of cosines is the only rule that starts. Take 7, 8 and 10, with the 10 opposite C: cos C = (49 + 64 - 100) / (2 x 7 x 8) = 13 / 112 = 0.1161, so C = 83.33 degrees.

A second pass gives A: cos A = (64 + 100 - 49) / (2 x 8 x 10) = 115 / 160 = 0.7188, so A = 44.05 degrees. The third angle is the remainder, B = 180 - 83.33 - 44.05 = 52.62 degrees. The area comes from Heron's formula with s = 12.5, and the square root of 12.5 x 5.5 x 4.5 x 2.5 is 27.81.

Check the sum before trusting any of it. The three angles have to add to 180 degrees, and a sum that misses by more than a rounding step means a side was copied wrong.

SidesLargest angleThe other twoArea
7, 8, 1083.33 degrees44.05 and 52.6227.81
6, 8, 1090.00 degrees36.87 and 53.1324.00
5, 6, 9109.47 degrees31.59 and 38.9414.14
5, 6, 778.46 degrees44.42 and 57.1214.70

The angle form, and what the sign tells you

cos C = (a^2 + b^2 - c^2) / (2ab) is the same equation solved for the angle, and the sign of the numerator carries the shape of the triangle. When c^2 is smaller than a^2 + b^2 the cosine is positive and C is acute. When the two are equal the cosine is zero and C is a right angle. When c^2 is larger, the cosine goes negative and C is obtuse.

That comparison is a one line test for the whole triangle. Sides 3, 4 and 5 give 25 against 25, so the angle opposite the 5 is exactly 90 degrees. Sides 4, 5 and 8 give 64 against 41, and cos C = -0.575, so the angle is 125.10 degrees and the triangle is obtuse. Sides 5, 6 and 9 give 81 against 61, cos C = -0.333 and an angle of 109.47 degrees.

The triangle inequality has to pass first. Sides 2, 3 and 10 fail it, because 2 + 3 is less than 10. No angle satisfies the rule for lengths that cannot close into a triangle, so the calculator reports the failure instead of a number.

Sidesc^2a^2 + b^2cos CAngle CType
3, 4, 525250.00090.00 degreesright
4, 5, 86441-0.575125.10 degreesobtuse
5, 6, 98161-0.333109.47 degreesobtuse
5, 6, 749610.20078.46 degreesacute
7, 8, 101001130.11683.33 degreesacute

Radians behave the same way, since the cosine does not care which unit the angle is written in. Convert once at the boundary and the arithmetic is identical. Spreadsheets and programming languages default to radians, so an answer that reads 1.45 instead of 83.33 usually means the conversion was skipped rather than the side lengths being wrong.

Precision deserves a note. A cosine close to 1 or -1 is flat, so an angle near 0 or 180 degrees is sensitive: a change of 0.001 in the cosine moves the angle by a fraction of a degree there, and by hundredths of a degree near 90. Carry four decimals through the intermediate steps and round the final angle to two.

Area from the same two sides

Two sides and the angle between them give the area directly: area = 0.5 x a x b x sin C. For 5 and 6 with 40 degrees between them, that is 0.5 x 5 x 6 x 0.6428 = 9.64.

From three sides, Heron's formula does the same job without an angle: s = (a + b + c) / 2, then the area is the square root of s(s - a)(s - b)(s - c). For 7, 8 and 10 that is the square root of 12.5 x 5.5 x 4.5 x 2.5, or 27.81, the same number the angle route returns once C is known.

The two formulas agree because sin C can be rebuilt from the law of cosines. sin C = sqrt(1 - cos^2 C), and cos C comes from the three sides, so Heron is the law of cosines wearing a different coat. Use Heron when no angle is given and the sine form when one is.

TriangleArea by 0.5 x a x b x sin CArea by Heron
5, 6, C = 40 degrees9.649.64
7, 8, 1027.8127.81
4, 5, 88.188.18
6, 6, 615.5915.59

When it beats the law of sines

The law of sines, a / sin A = b / sin B = c / sin C, is easier when you already know an angle and the side opposite it. The law of cosines wins whenever the known data is two sides and the angle between them, or three sides, because those are exactly the cases the sine rule cannot open.

The sine rule also has an ambiguous case. Given two sides and a non included angle it can return two different triangles, and both are valid. The cosine form returns one angle from three sides with no ambiguity, which makes it the safer starting point for a solver that has to commit to an answer.

Known dataLaw of sinesLaw of cosines
Three sides (SSS)cannot startone angle per pass
Two sides and the included angle (SAS)cannot startthird side in one step
Two angles and a side (ASA, AAS)one stepneeds a detour
Two sides and a non included angle (SSA)two possible trianglesa quadratic with two roots

Triangulation is the practical name for chaining these triangles together. A survey network fixes two points, measures the baseline, then intersects to place a third, and each new vertex is checked against the cosine rule before it is accepted. Bearings and azimuths enter as angles at a vertex, and the distances come out in the same units as the baseline.

Where the rule shows up in the field

A boat runs 30 nautical miles, turns, and runs 45 more, with 65 degrees between the two legs at the turn. The straight line from start to finish is the third side: the square root of 900 + 2,025 - 2 x 30 x 45 x cos 65, which is 42.24 nautical miles. The same arithmetic sizes a crosswind leg in a flight plan or a cable run between two fixed points.

Surveyors use it the other way round. Measure two sides from a baseline and the angle between them, and the third distance falls out without occupying that point. The National Geodetic Survey's geodetic toolkit applies the same triangle algebra to the curved surface of the earth, where the plane version here is the first approximation.

On a building site the 3-4-5 triangle is the same rule in disguise. 9 + 16 = 25 means the angle is 90 degrees, and 6-8-10 scales it up without changing the corner. Any triple where the squares balance gives a square corner, which is why the trick survives on sites with no calculator in sight.

Long distances need the spherical version, cos a = cos b cos c + sin b sin c cos A, where the sides are measured as angles at the centre of the earth. Meridians converge toward the poles, so a plane triangle stops matching the ground once the legs run to hundreds of miles. Over a few miles the plane rule here stays within a metre or two, which is why surveyors and pilots both keep the flat version for local work.

Frequently asked questions

What is the law of cosines?

c^2 = a^2 + b^2 - 2ab cos C, where C is the angle between sides a and b and c is the side opposite it. It works for every triangle, and at 90 degrees it reduces to the Pythagorean theorem.

How do I find an angle from three sides?

Use cos C = (a^2 + b^2 - c^2) / (2ab) and take the inverse cosine. For sides 7, 8 and 10 the angle opposite the 10 is 83.33 degrees.

What is the difference between the law of sines and the law of cosines?

The law of sines needs an angle and its opposite side, so it handles ASA and AAS. The law of cosines handles three sides or two sides with the included angle, and it returns one answer where the sine rule can return two.

How do I find the third side with a = 5, b = 6 and C = 40 degrees?

c^2 = 25 + 36 - 2 x 5 x 6 x cos 40 = 15.04, so c = 3.88. The remaining angles are 55.98 and 84.02 degrees, and the area is 9.64.

Does the law of cosines work for right triangles?

Yes, and it becomes the Pythagorean theorem there. The cosine of 90 degrees is zero, so the 2ab cos C term drops out. Sides 3, 4 and 5 give 25 = 9 + 16.

How do I know whether a triangle is obtuse?

Compare the square of the longest side with the sum of the other two squares. If c^2 is larger, the angle opposite c is obtuse. Sides 4, 5 and 8 give 64 against 41, cos C = -0.575 and an angle of 125.10 degrees.

What is the ambiguous case?

Two sides and a non included angle can fit two different triangles. The law of sines shows it as two valid angles, and the law of cosines shows it as a quadratic in the unknown side with two positive roots.

Do the angles always add up to 180 degrees?

Yes, in plane geometry. Sum the three angles you get as a check, and a total that misses 180 by more than a rounding step means one of the inputs is wrong.

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

Area = 0.5 x a x b x sin C once an angle is known. For 5 and 6 with 40 degrees between them that is 9.64. From three sides, Heron's formula gives the same number without an angle.

Can the law of cosines handle an equilateral triangle?

Yes. Sides 6, 6 and 6 give cos C = (36 + 36 - 36) / 72 = 0.5, so every angle is 60 degrees and the area is 15.59.

What units should the sides be in?

Any consistent unit: inches, meters, miles or nautical miles. The answer comes back in the same unit, and the angles are reported in degrees.

What if the three sides cannot form a triangle?

The triangle inequality fails, and no angle satisfies the rule. Sides 2, 3 and 10 fail because 2 + 3 is less than 10, and the calculator reports that instead of a number.

Spotted a wrong number or a broken result?

More Everyday tools

See all Everyday tools

Fee schedules, rates and rules change without notice. Always confirm important figures with the official source before you rely on them.