🇺🇸 USC
Math & Conversion
📐

Law of Cosines Calculator

Solve SAS and SSS triangles with the cosine rule, step by step

Last updated September 6, 2026

Method: The law of cosines c² = a² + b² − 2ab cos C and its rearranged form cos C = (a² + b² − c²) / (2ab), the 180° angle sum of a plane triangle, Heron's formula for the area, and the triangle inequality as the validity test.

Included: SAS and SSS input, all three sides and all three angles, the cosine of each angle, area by Heron's formula, perimeter, circumradius, inradius, an acute / right / obtuse classification, and a numbered derivation of every step.

Not included: AAS, ASA and SSA input (those start with the law of sines), spherical or non-Euclidean triangles, exact radical answers, and coordinate geometry. Angles are entered in degrees.

Disclaimer: Free educational tool. The formula is exact, but displayed values are rounded, so confirm any safety-critical surveying, machining or structural figure against your own measurements.

Two sides and the angle between them. The law of cosines finds the third side first, then both remaining angles.

📐 Law of cosines solution

6.67third side c in
SAS case · Obtuse triangle · area 26.48
Angle A
46.24°
Angle B
96.76°
Angle C
37°
Side a
8 in
Side b
11 in
Side c
6.67 in
💡

Why the answer looks like this

Because C is under 90 degrees, cos C is positive and 2ab x cos C is subtracted from a^2 + b^2. The third side comes out shorter than the right-angle value of 13.6015.

🔺 Full solution

VertexAngleCosineOpposite side
A46.24°0.69178 in
B96.76°-0.117811 in
C37°0.79866.67 in
Perimeter
25.67 in
Area (Heron)
26.48
Circumradius R
5.54 in
Inradius r
2.06 in

Step by step

  1. Write the law of cosines for the unknown side: c^2 = a^2 + b^2 - 2ab x cos C
  2. Substitute: c^2 = 8^2 + 11^2 - 2 x 8 x 11 x cos 37 degrees
  3. cos 37 degrees = 0.798636, so the correction term 2ab x cos C = 140.5598
  4. c^2 = 64 + 121 - (140.5598) = 44.4402
  5. Take the square root: c = 6.6663
  6. Angle A: cos A = (b^2 + c^2 - a^2) / (2bc) = 0.691671, so A = 46.2375 degrees
  7. Angle B: cos B = (a^2 + c^2 - b^2) / (2ac) = -0.117754, so B = 96.7625 degrees
  8. Check the angle sum: 46.2375 + 96.7625 + 37 = 180 degrees
  9. Area = 1/2 x a x b x sin C = 0.5 x 8 x 11 x 0.601815 = 26.4799

Cross-check: the law of sines ratio side / sin(angle) is 11.08 for A, 11.08 for B and 11.08 for C. All three match, which confirms the solution.

Free educational tool. Angles are entered and shown in degrees, the angle sum is fixed at 180 degrees (plane geometry), and displayed values are rounded. The law of cosines is exact math, so the only error here is rounding. For surveying, machining or structural work, confirm against your own measurements.

Law of cosines: everything you need to know

The law of cosines (also called the cosine rule) links the three sides of any triangle to one of its angles: c² = a² + b² − 2ab cos C. It solves the two cases the sine rule cannot start on, SAS and SSS. Example: with sides 8 and 11 and a 37° angle between them, the third side is 6.6663 and the area is 26.4799 square units.

Two sister pages cover the neighboring questions. The Law of Sines Calculator handles AAS, ASA and the ambiguous SSA case, where you already know an angle and the side opposite it. The Triangle Calculator takes whatever mix of sides and angles you have and returns the full solution without you choosing a rule. Use this page when you want the cosine rule itself shown line by line, either to find a third side from SAS data or to turn three measured lengths into three angles.

How the law of cosines works

Every triangle obeys the same relationship between a side and the angle across from it:

c² = a² + b² − 2ab × cos C

Read it as the Pythagorean theorem plus a correction. If the angle C between sides a and b were exactly 90°, cos C would be 0, the last term would vanish, and you would be left with c² = a² + b². Anything other than a right angle needs the correction term 2ab cos C, and the sign of the cosine tells you which way it pushes. For an acute angle the cosine is positive, so you subtract something and the third side comes out shorter than the right-angle value. For an obtuse angle the cosine is negative, subtracting a negative adds length, and the third side comes out longer.

The three forms you actually use

The rule is symmetric, so it can be written once for each vertex, and it can be rearranged to give an angle instead of a side. Those are the four expressions this calculator applies:

a² = b² + c² − 2bc × cos A
b² = a² + c² − 2ac × cos B
c² = a² + b² − 2ab × cos C
cos C = (a² + b² − c²) ÷ (2ab)

The first three take SAS data and hand you the missing side. The fourth takes SSS data and hands you an angle, and because inverse cosine returns exactly one value between 0° and 180°, the answer is never ambiguous. That single-answer property is the reason many people reach for the cosine rule first and only then switch to the sine rule for the remaining angles.

Worked example 1: SAS, two sides and the angle between them

Suppose a = 8, b = 11, and the angle between those two sides is C = 37°. Work through it in five moves:

  1. Square the known sides: a² = 64 and b² = 121, so a² + b² = 185.
  2. Build the correction term: 2ab = 2 × 8 × 11 = 176, and cos 37° = 0.798636, so 2ab cos C = 140.5598.
  3. Subtract: c² = 185 − 140.5598 = 44.4402, so c = 6.6663.
  4. Find angle A from the rearranged rule: cos A = (121 + 44.4402 − 64) / (2 × 11 × 6.6663) = 0.691671, so A = 46.2375°.
  5. Find angle B the same way: cos B = (64 + 44.4402 − 121) / (2 × 8 × 6.6663) = −0.117754, so B = 96.7625°.

Check the angle sum: 46.2375 + 96.7625 + 37 = 180.0000°. The area is 0.5 × 8 × 11 × sin 37° = 0.5 × 88 × 0.601815 = 26.4799 square units, and Heron's formula on the solved sides (s = 12.8332) returns the identical 26.4799, which is a clean cross-check. The perimeter is 25.6663 and the circumradius is 5.5385. Notice that angle B came out obtuse even though the only angle you were given was a modest 37°: the cosine rule found that on its own, with no ambiguity to resolve.

Worked example 2: SSS, three measured sides

Now take a triangle whose sides measure 7, 9 and 12, with no angle known at all. Use the rearranged form three times:

  • cos C = (49 + 81 − 144) / (2 × 7 × 9) = −14 / 126 = −0.111111, so C = 96.3794°.
  • cos A = (81 + 144 − 49) / (2 × 9 × 12) = 176 / 216 = 0.814815, so A = 35.4309°.
  • cos B = (49 + 144 − 81) / (2 × 7 × 12) = 112 / 168 = 0.666667, so B = 48.1897°.

The three angles add to 180.0000°, confirming the arithmetic. For the area, the semiperimeter is s = 28 / 2 = 14, and Heron's formula gives the square root of 14 × 7 × 5 × 2 = the square root of 980 = 31.305 square units. The circumradius is 6.0374 and the inradius is 2.2361. The negative cosine on angle C is the shape test in action: 12² = 144 exceeds 7² + 9² = 130, so the triangle is obtuse.

How the third side changes with the included angle

Hold two sides fixed at a = 10 and b = 14 and swing the angle between them. The table shows the correction term, the resulting third side, and the area at each angle, all computed with the formula above.

Angle C cos C 2ab cos C Side c Area
20°0.9397263.1132.895.734623.94
30°0.8660242.4953.517.315335.00
45°0.7071197.9998.019.900049.50
60°0.5000140.00156.0012.490060.62
75°0.258872.47223.5314.950967.61
90°0.00000.00296.0017.204770.00
105°−0.2588−72.47368.4719.195667.61
120°−0.5000−140.00436.0020.880660.62
135°−0.7071−197.99493.9922.225949.50
150°−0.8660−242.49538.4923.205335.00

Two things stand out. The 90° row is pure Pythagoras: 100 + 196 = 296, and the square root of 296 is 17.2047. And the area column is symmetric around 90° while the side column is not, because area depends on sin C, which is equal at 75° and 105°, while the side depends on cos C, which flips sign.

Shape test: what three sides tell you before you solve

In SSS work, comparing the longest side squared with the sum of the other two squares tells you the shape immediately, and the cosine rule then gives the exact angle. Each row below was computed with cos = (x² + y² − z²) / (2xy) for the largest angle, with Heron's formula for the area.

Sides cos of largest angle Largest angle Shape Area
3, 4, 50.000090.00°Right6.0000
5, 12, 130.000090.00°Right30.0000
8, 15, 170.000090.00°Right60.0000
10, 10, 100.500060.00°Acute (equilateral)43.3013
4, 5, 60.125082.82°Acute9.9216
6, 7, 80.250075.52°Acute20.3332
7, 9, 12−0.111196.38°Obtuse31.3050
2, 3, 4−0.2500104.48°Obtuse2.9047
5, 5, 8−0.2800106.26°Obtuse (isosceles)12.0000

The three Pythagorean triples land on a cosine of exactly zero, which is what "right triangle" means in cosine-rule language. For a quick check of that special case on its own, the Pythagorean Theorem Calculator is faster.

How the angle grows as the opposite side grows

Fix a = 8 and b = 11 and let the third side c vary. The triangle inequality allows c anywhere strictly between 11 − 8 = 3 and 8 + 11 = 19; outside that range the shape cannot close. Inside it, every length of c produces exactly one angle C.

Side c cos C Angle C Area
40.960216.21°12.286
50.909124.62°18.330
6.66630.798637.00°26.480
80.687546.57°31.952
100.483061.12°38.528
120.233076.53°42.789
14−0.062593.58°43.914
16−0.4034113.79°40.261
18−0.7898142.16°26.990

The area peaks near c = 14, which is close to the 90° row, exactly as expected: for two fixed sides the area 1/2 ab sin C is largest when the included angle is a right angle. The 6.6663 row is the SAS example from earlier read backwards, which is a good way to confirm that the two modes of this calculator agree.

How to use this calculator

  1. Pick the case. Choose SAS if you know two sides and the angle between them. Choose SSS if you have measured all three sides.
  2. Label consistently. Side a sits opposite angle A, side b opposite B, side c opposite C. In SAS mode, the two sides you enter are a and b, and the angle you enter is the one they form.
  3. Type the values. Enter lengths in whatever unit you are working in, and the angle in degrees. The result recalculates as you type.
  4. Read the headline. In SAS mode it shows the third side; in SSS mode it shows the largest angle. The tiles below carry all three angles and all three sides.
  5. Check the derivation. The numbered steps reproduce the substitution, the correction term, the square root, and each inverse cosine, so you can copy the work into homework or a job sheet.
  6. Set the display. Choose a unit label and one to four decimal places. Only the display rounds; the math always runs at full precision.

Who this calculator is for

  • Trigonometry and precalculus students who need the cosine rule shown step by step, not just an answer.
  • Carpenters and deck builders laying out a non-square corner from two run lengths and an angle.
  • Surveyors and site technicians closing a traverse from three measured distances.
  • Machinists and fabricators checking a bolt-circle chord or a mitered joint against a print.
  • Navigators and pilots resolving a course-change leg where the turn angle is known but the closing distance is not.
  • Anyone with three tape measurements who needs the angles between them without a protractor.

A real-world example: a deck corner

You are framing a deck where two runs leave the same corner post. One run is 12 ft, the other is 18 ft, and the angle between them is 110° rather than a square 90°. How long is the diagonal that closes the shape, and what angles do the runs make with it? Apply the cosine rule: cos 110° = −0.342020, so 2ab cos C = 2 × 12 × 18 × (−0.342020) = −147.7527. Then c² = 144 + 324 + 147.7527 = 615.7527, and the diagonal is 24.8144 ft, a little under 24 ft 9.8 in. The remaining angles follow from the rearranged rule: 42.9719° at the end of the 12 ft run and 27.0281° at the end of the 18 ft run, adding with 110° to a clean 180°. The enclosed area is 0.5 × 12 × 18 × sin 110° = 101.4868 square feet, which is what you would order decking for. Note how the obtuse angle stretched the diagonal well past the right-angle answer of 21.6333 ft.

Key terms explained

  • Included angle: the angle formed between two named sides. In SAS data it is the angle you know, and it is opposite the side you are solving for.
  • Oblique triangle: any triangle without a 90° angle. The cosine rule was built for these; right triangles are just the special case where the correction term is zero.
  • Triangle inequality: the requirement that the two shorter sides add up to more than the longest side. It is the validity test for SSS input.
  • Heron's formula: an area formula that needs only the three sides, Area = the square root of s(s − a)(s − b)(s − c) with s the semiperimeter.
  • Circumradius (R): the radius of the circle through all three vertices, equal to abc divided by four times the area.
  • Inradius (r): the radius of the largest circle that fits inside the triangle, equal to the area divided by the semiperimeter.
  • Inverse cosine (arccos): the function that turns a cosine back into an angle. It returns a single value from 0° to 180°, which is why the cosine rule never produces two candidate triangles.

What changes the result the most

  • The included angle. It is the most sensitive input in SAS mode. Moving from 60° to 120° on the same 10 and 14 sides stretches the third side from 12.49 to 20.8806, a 67% jump.
  • The sign of the cosine. Crossing 90° flips the correction term from subtracting length to adding it, which is why obtuse triangles look so different from acute ones with the same two sides.
  • Measurement error in the longest side. In SSS mode the largest angle is the one most affected by a tape that reads a fraction long, because it depends on the squared value of that side.
  • Near-degenerate shapes. When the three sides barely satisfy the triangle inequality, the cosine is close to −1 and a tiny change in one length swings the angle by degrees.
  • Rounding partway through. Rounding the cosine to two decimals before the inverse cosine can move the final angle by more than a tenth of a degree.

Tips for a clean, accurate answer

  • Solve the largest angle first in SSS mode. It is the only one that can be obtuse, and the cosine rule handles it correctly, whereas finishing with the sine rule on a big angle can hide an obtuse answer.
  • Cross-check the angle sum. Every solved triangle should total 180°. This calculator prints the sum for exactly that reason.
  • Cross-check the area two ways. Heron's formula and 1/2 ab sin C must agree; if they do not, a side or angle got mislabeled.
  • Keep full precision. Carry unrounded values through the derivation and round only the final display, which is what the calculator does internally.
  • Use consistent units. All three lengths must be in the same unit. Mixing feet and inches is the single most common source of wrong answers in shop work.

Limitations and assumptions

  • It assumes plane (Euclidean) geometry, so the angle sum is exactly 180°. Long-range geodesy on the curved surface of the earth needs spherical trigonometry instead.
  • It takes SAS and SSS only. AAS, ASA and SSA data start with the law of sines, and the ambiguous SSA case needs the extra height test that page provides.
  • Answers are decimal, not symbolic. A textbook answer of the square root of 44.4402 is shown as 6.6663 here.
  • Angles are entered and displayed in degrees, not radians or gradians.
  • Results are only as good as your measurements. A tape that is off by 1/8 in or a protractor read to the nearest degree limits the real accuracy far more than the arithmetic does.

How it compares to related calculators

This page answers "what are the missing parts of this triangle when I have SAS or SSS data?" For a different starting point, a sister tool fits better:

Sources

Everything on this page is deterministic plane geometry, so there are no agency figures to cite. The law of cosines, its rearranged form for an angle, Heron's formula, the triangle inequality and the 180° angle sum are exact theorems of Euclidean geometry, provable from first principles and independent of any measurement standard or jurisdiction. The only outside convention used here is the definition of the degree as 1/360 of a full turn and the units you attach to your own lengths; for the exact definitions of the inch (25.4 mm exactly) and the other US customary units you may be measuring in, the reference is NIST Special Publication 811, the National Institute of Standards and Technology guide to the SI and to US customary conversions. No non-primary sources are used, and no market, tax or health data appears on this page.

⚠️ Common mistakes & edge cases

Using an angle that is not between the two sides

SAS means the known angle sits between the two known sides. If your angle is opposite one of them, that is SSA, and it belongs on the law of sines page where the ambiguous case is handled. Feeding SSA data into the SAS box silently solves a different triangle.

Forgetting the square root

The formula returns c², not c. In the worked example, stopping at 44.4402 and writing that as the side is a classic slip; the answer is the square root, 6.6663.

Dropping the minus sign on an obtuse cosine

cos 110° is −0.342020, not 0.342020. Subtracting a negative adds length, which is why the deck diagonal came out 24.8144 ft instead of 17.8954 ft. Losing that sign is the most common arithmetic error in the whole rule.

Finishing an SSS solve with the sine rule

After finding one angle you can switch to the sine rule, but inverse sine always returns an acute value. If the remaining angle is actually obtuse, you get the wrong answer. Solve the largest angle with the cosine rule first, or simply use the cosine rule for all three.

Entering impossible side lengths

Sides of 2, 3 and 9 cannot form a triangle, because 2 + 3 is less than 9. The formula would ask for the inverse cosine of −5.6667, which does not exist. The calculator catches this and tells you the triangle inequality failed.

Calculating in radian mode by accident

A handheld calculator left in radians turns cos 37 into 0.765414 instead of 0.798636, and the third side changes from 6.6663 to a wrong value. This page always uses degrees, so it is a good way to check a handheld answer.

Note: This is an educational tool. The geometry is exact, but displayed values are rounded, so verify any structural, machining or surveying figure against your own measurements before you cut.

❓ Frequently asked questions

What is the law of cosines?

The law of cosines relates the three sides of any triangle to one of its angles: c squared = a squared + b squared - 2ab x cos C, where C is the angle between sides a and b. It works for every plane triangle, acute, right or obtuse. When C is exactly 90 degrees, cos C is 0 and the formula reduces to the Pythagorean theorem, so the cosine rule is the general version of that theorem.

When do I use the law of cosines instead of the law of sines?

Use the law of cosines when you know three sides (SSS) or two sides and the angle between them (SAS). In those two cases you do not have a complete side-angle pair, so the law of sines cannot start. Use the law of sines when you know an angle together with the side opposite it, which covers AAS, ASA and SSA. A common workflow is to use the cosine rule once, then finish the triangle with the faster sine rule.

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

Rearrange the formula to isolate the cosine: cos C = (a squared + b squared - c squared) / (2ab), then take the inverse cosine. For a triangle with sides 7, 9 and 12, cos C = (49 + 81 - 144) / (2 x 7 x 9) = -0.111111, so C = 96.3794 degrees. The same rearrangement finds any angle: put the side opposite that angle on the left of the subtraction.

Can the law of cosines give two answers like the ambiguous SSA case?

No. Inverse cosine returns exactly one angle between 0 and 180 degrees, and every triangle angle lives in that range, so there is never a second candidate. That is the practical advantage over the law of sines, where an inverse sine has a supplement with the same value and SSA data can describe two different triangles. If you have SSA data, solving for the third side with the cosine rule turns it into a quadratic that can have two positive roots, and those two roots are the two triangles.

Is the law of cosines the same as the Pythagorean theorem?

The Pythagorean theorem is the special case where the angle between the two known sides is 90 degrees. Set C = 90 in c squared = a squared + b squared - 2ab x cos C, and because cos 90 degrees = 0 the whole correction term disappears, leaving c squared = a squared + b squared. With sides 10 and 14 the right-angle third side is 17.2047. At 60 degrees it shrinks to 12.49, and at 120 degrees it grows to 20.8806.

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

Two routes give the same number. In the SAS case use Area = 1/2 x a x b x sin C with the angle you already know: with a = 8, b = 11 and C = 37 degrees the area is 0.5 x 8 x 11 x 0.601815 = 26.4799 square units. In the SSS case use Heron's formula on the three sides: s = (a + b + c) / 2, then Area = the square root of s(s - a)(s - b)(s - c). For 7, 9 and 12 that is the square root of 14 x 7 x 5 x 2 = 31.305 square units.

What does a negative cosine mean in the result?

A negative cosine means that angle is obtuse, larger than 90 degrees. Cosine is positive from 0 to 90 degrees, zero at exactly 90, and negative from 90 to 180. So the sign of the cosine is an instant shape test: if the longest side squared is bigger than the sum of the other two squares, the cosine of the largest angle comes out negative and the triangle is obtuse. With sides 7, 9 and 12, 144 is greater than 49 + 81 = 130, and the largest angle is 96.3794 degrees.

Why does my calculator say no triangle exists?

In SSS mode the three lengths must satisfy the triangle inequality: the two shorter sides added together must exceed the longest side. Sides of 2, 3 and 9 fail, because 2 + 3 = 5 is less than 9, and no triangle can close. In SAS mode the included angle must be strictly between 0 and 180 degrees; at 0 or 180 the three points fall on one straight line and there is no triangle to solve.

Does the law of cosines work in radians?

Yes. The rule is a statement about the cosine function, not about the unit you write the angle in, so it holds in radians exactly as it does in degrees. Just stay consistent: in radians the angle sum is pi rather than 180. This calculator uses degrees, which is what US homework, surveying and shop drawings normally use. To convert, multiply degrees by pi divided by 180.

Which side should I call a, b and c?

The labels are yours to choose, but one rule must hold: each lowercase side sits opposite the matching uppercase angle, so side c is opposite angle C. In SAS mode enter the two sides that form the known angle as a and b, and the angle between them as C. The answer, side c, is the one across from that angle. If you mislabel, the arithmetic still runs but you will solve a different triangle.

How accurate is this law of cosines calculator?

The math runs in full double precision in your browser and only the display is rounded, so the answer is exact to far more digits than any tape measure or protractor. Rounding an intermediate value by hand is what usually creates disagreement with a textbook. In the SAS example, carrying the unrounded 44.4402 for c squared gives c = 6.6663, while rounding cos 37 degrees to 0.80 first would give 6.6483, an error in the second decimal.

Is this law of cosines calculator free?

Yes. It is completely free, with no sign-up and no cap on how many triangles you solve. Everything is computed in your browser with JavaScript's built-in math library, so nothing you type is sent to a server and the page keeps working if your connection drops. Switch between SAS and SSS as often as you like and change the number of decimal places to match your homework or your shop tolerance.

💡 Good to know

The cosine rule contains Pythagoras

Set the included angle to 90° and the term 2ab cos C becomes zero, leaving c² = a² + b². With sides 10 and 14 that is 296, and the square root is 17.2047. Every other angle just bends that answer up or down.

One answer, always

Inverse cosine returns a single angle between 0° and 180°, so SAS and SSS data never produce two triangles. That is the opposite of the SSA case on the law of sines page, where the same three numbers can describe two different shapes.

Three sides are enough for everything

From SSS data alone the cosine rule gives all three angles, Heron's formula gives the area, and those together give the circumradius and inradius. For sides 7, 9 and 12 that is an area of 31.305, a circumradius of 6.0374 and an inradius of 2.2361, all from three tape measurements.

Related Calculators