Law of Cosines Calculator

The law of cosines, c² = a² + b² − 2ab·cos C, finds the third side of a triangle from two sides and the angle between them, or any angle from three sides. With sides 5 and 7 and a 60° angle between them, c = √39 ≈ 6.24 (see the steps).

Solve a triangle with the law of cosines

Pick what you know. Sides a, b and c sit across from angles A, B and C. The answer updates as you type.

Angle C sits between sides a and b, across from the side c you want. Fractions such as 7/2 work.

Examples:

How to Use This Calculator

  1. Pick what you know

    SAS for two sides and the angle between them, SSS for three sides, SSA for two sides and another angle.

  2. Type the measurements

    Angles in degrees. Sides in any one unit, as decimals or fractions such as 7/2.

  3. Read the triangle

    You get the missing side or angle (exact when possible), the whole triangle, its area, and every step.

What is the law of cosines?

The law of cosines connects the three sides of any triangle with one of its angles. Label the sides a, b and c, and the angles across from them A, B and C. Then c² = a² + b² − 2ab·cos C. Outside the US it is usually called the cosine rule.

It is the Pythagorean theorem with a correction for angles that are not 90°. When C is a right angle, cos C = 0, the last term vanishes, and you are left with c² = a² + b². When C is smaller than 90°, cos C is positive, so something is taken away and c comes out shorter. When C is larger than 90°, cos C is negative, so something is added and c comes out longer. The calculator draws this as three bars under every answer.

The law of cosines formula

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 three lines are one rule written for each side: the side on the left is always the one across from the angle in the cosine. The last line is the same formula solved for the angle, which is the form you need when all three sides are known.

When to use the law of cosines

The choice depends on what you are given. The law of sines needs a side and the angle across from it. For SAS and SSS you have no such pair, so you start with the law of cosines.

Which rule to use for each set of given parts
You know Case Use
Two sides and the angle between themSASLaw of cosines
All three sidesSSSLaw of cosines
Two angles and the side between themASALaw of sines
Two angles and another sideAASLaw of sines
Two sides and an angle not between themSSAEither; check for two triangles
A right angle and two more partsRightPythagoras and SOH CAH TOA

After the law of cosines gives you one missing part, you have a side and its opposite angle, so the law of sines can finish the job. The calculator keeps using the law of cosines instead, because the inverse cosine never mixes up an angle with its supplement the way the inverse sine can.

How to find a missing side (SAS)

Sides a = 5 and b = 7 meet at a 60° angle. Put them into c² = a² + b² − 2ab·cos C: c² = 25 + 49 − 2 × 5 × 7 × cos 60°. Since cos 60° = 1/2, the last term is 35, so c² = 74 − 35 = 39 and c = √39 ≈ 6.245. A common slip is to subtract 2ab before multiplying by the cosine; the whole product 2ab·cos C is one term.

Solve 5, 7 and 60° step by step

How to find a missing angle (SSS)

With sides 5, 6 and 7, use the rearranged form for each angle. For C, across from the 7: cos C = (5² + 6² − 7²) ÷ (2 × 5 × 6) = 12 ÷ 60 = 1/5, so C = cos⁻¹(0.2) ≈ 78.46°. The same way, A ≈ 44.42° and B ≈ 57.12°, and the three add up to 180°.

A negative cosine means an obtuse angle. For sides 7, 8 and 13, cos C = (49 + 64 − 169) ÷ 112 = −1/2, so C is exactly 120°. If the sides cannot form a triangle at all (the longest is not shorter than the other two together), the cosine comes out below −1 and the calculator says so.

Show the obtuse 7-8-13 triangle

Law of cosines examples

Each row opens in the calculator with the full triangle and the steps. Decimals are rounded to two places.

Worked law of cosines examples
Given Case Answer
a = 5, b = 7, C = 60° sas c = √39 ≈ 6.24
a = 3, b = 4, C = 90° sas c = 5
a = 6, b = 9, C = 120° sas c = 3√19 ≈ 13.08
a = 8, b = 11, C = 37° sas c ≈ 6.67
a = 5, b = 6, c = 7 sss C ≈ 78.46° (cos C = 1/5)
a = 7, b = 8, c = 13 sss C = 120° (cos C = −1/2)
a = b = c = 4 sss every angle = 60°
a = 9, b = 10, c = 17 sss C ≈ 126.87°

The ambiguous case (SSA)

When the known angle is not between the two known sides, the measurements may fit two different triangles, one, or none. Picture side b fixed at angle A, and side a swinging from its far end like a gate: it can hit the base line twice, touch it once, or fall short.

The law of cosines shows this as a quadratic. Take a = 6, b = 8 and A = 40°. Putting them into a² = b² + c² − 2bc·cos A gives 36 = 64 + c² − 16c·cos 40°, or c² − 12.26c + 28 = 0. It has two positive roots, c ≈ 9.22 and c ≈ 3.04, so two triangles fit. The quick test compares a with the height h = b·sin A ≈ 5.14: a is longer than h but shorter than b, which is exactly the two-triangle case.

Show both triangles

How many triangles fit in the SSA case
Angle A acute, h = b·sin A Triangles
a < hNone
a = hOne (right angle at B)
h < a < bTwo
a ≥ bOne

If angle A is 90° or more, there is one triangle when a is longer than b and none otherwise.

Law of cosines word problems

How far apart are two boats?

Two boats leave the same harbor. One sails 20 km, the other 28 km, and their courses are 55° apart. The harbor and the two boats form a triangle with the 55° angle between the known sides, so this is SAS: d² = 20² + 28² − 2 × 20 × 28 × cos 55° ≈ 541.59, and d ≈ 23.27 km.

Show the two boats

The corners of a triangular plot

A plot of land has sides of 40 m, 55 m and 70 m. All three sides are known, so this is SSS. The largest angle sits across from the 70 m side: cos C = (40² + 55² − 70²) ÷ (2 × 40 × 55) = −275 ÷ 4,400, so C ≈ 93.58°, a little over a right angle. The other corners are about 34.77° and 51.64°, and Heron's formula gives an area of about 1,098 m².

Show the plot of land

Frequently Asked Questions

What is the law of cosines formula?

c² = a² + b² − 2ab·cos C, where C is the angle between sides a and b, across from side c. The same rule works for the other sides: a² = b² + c² − 2bc·cos A and b² = a² + c² − 2ac·cos B.

When do you use the law of cosines?

Use it 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. For two angles and a side, the law of sines is quicker.

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

Rearrange the formula to cos C = (a² + b² − c²) ÷ (2ab), work out the right side, then take the inverse cosine. For sides 5, 6 and 7, cos C = (25 + 36 − 49) ÷ 60 = 1/5, so C ≈ 78.46°.

Show the 5-6-7 triangle

Is the cosine rule the same as the law of cosines?

Yes. "Cosine rule" is the usual name in the UK, Australia and much of the world, and "law of cosines" is the usual name in the US. Both mean c² = a² + b² − 2ab·cos C.

Can you use the law of cosines on a right triangle?

Yes, and it turns into the Pythagorean theorem. With C = 90°, cos C = 0, so the 2ab·cos C term disappears and c² = a² + b². For 3, 4 and 90°, c = 5.

Show 3, 4 and 90°

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

The law of sines links each side to the sine of the angle across from it, a ÷ sin A = b ÷ sin B = c ÷ sin C, so it needs a matching side and angle pair. The law of cosines links three sides and one angle, so it works for SAS and SSS, where no such pair is known.

How do you know if SSA gives two triangles?

Compare side a, across from the known angle A, with the height h = b·sin A. If a is shorter than h, there is no triangle. If a equals h, there is one right triangle. If a is between h and b, there are two, and if a is at least b, there is one.

Show a case with two triangles