Law of Cosines Calculator
Solve any non-right triangle with the law of cosines. Find a missing side from two sides and the included angle, or find an angle from all three sides, with every substitution shown.
Angles are entered and reported in degrees. The law of cosines works for every triangle, right or not, and reduces to the Pythagorean theorem when the included angle is 90 degrees.
Most triangles in the real world are not right triangles. Roofs, bridges, survey plots, and navigation fixes all involve triangles with no 90-degree corner, where the Pythagorean theorem cannot reach. The law of cosines is the tool that generalizes Pythagoras to every triangle, and the Law of Cosines Calculator applies it for you in both directions.
Give the calculator two sides and the angle between them, and it returns the third side. Give it all three sides, and it returns the angle opposite any side you choose. Each result arrives with the formula, the substitution, and the final step spelled out, so the answer teaches as well as computes.
This guide covers both modes in detail, explains why the law works, walks through four worked examples including the Pythagorean special case, flags the mistakes that cost students marks, and answers the fifteen most common questions.
What Does the Law of Cosines Calculator Do?
The Law of Cosines Calculator solves non-right triangles using the relation c2 = a2 + b2 − 2ab·cos(C). In side-finding mode you enter sides a and b plus the included angle C, and the calculator returns side c with the cosine evaluated and the square root taken.
In angle-finding mode you enter all three sides, and it returns the angle C opposite the third side using the rearranged form cos(C) = (a2 + b2 − c2) / 2ab. It also reports the perimeter and classifies the angle as acute, right, or obtuse.
How to Use the Law of Cosines Calculator
Pick your mode with the selector buttons. For a missing side, type the two known sides and the angle squeezed between them into the three boxes. For a missing angle, type all three sides, placing the side opposite your target angle in the third box.
Press Calculate and check the headline first, then the steps panel, which shows the formula, the numbers substituted, and the arithmetic. Angles are entered and answered in degrees throughout. Reset reloads the page for a fresh problem.
The Formula and Why It Works
The law of cosines states that c2 = a2 + b2 − 2ab·cos(C), where C is the angle between sides a and b and c is the side opposite it. The 2ab·cos(C) term is a correction to the Pythagorean sum that accounts for the angle not being square.
When C is 90 degrees, cos(C) is zero, the correction vanishes, and you recover c2 = a2 + b2 exactly. When C is acute, the correction subtracts and the opposite side shortens; when C is obtuse, the cosine goes negative, the correction adds, and the side stretches longer than Pythagoras would predict.
Finding a Side From Two Sides and the Included Angle
This SAS mode is the calculator’s most-used path. The included angle is the one physically between your two known sides, which matters enormously: using a non-included angle here answers a different question entirely and belongs to the law of sines instead.
Type the sides in any order, since a and b play symmetric roles, and enter the angle in degrees. The calculator evaluates the cosine, forms c2, and takes the positive square root, because side lengths are positive by definition.
Finding an Angle From Three Sides
The SSS mode runs the formula backwards. With all three sides known, the angle is fully determined, and the rearranged formula cos(C) = (a2 + b2 − c2) / 2ab isolates it. The calculator applies arccosine and converts to degrees.
Before computing, it checks the triangle inequality: each side must be shorter than the sum of the other two. Impossible triples are rejected with an explanation rather than producing a nonsense angle from an out-of-range cosine.
Worked Example: Finding the Third Side
Take a = 7, b = 10, and included angle C = 60°, the calculator’s default SAS setup.
First: write the formula. c2 = a2 + b2 − 2ab·cos(C).
Then: substitute. c2 = 49 + 100 − 2(7)(10)cos(60°) = 149 − 140(0.5) = 149 − 70 = 79.
Next: take the square root. c = √79 ≈ 8.8882.
Answer: c ≈ 8.8882, a touch shorter than side b, which feels right for a 60-degree included angle.
Worked Example: Finding the Angle
Take sides a = 7, b = 10, c = 8 in SSS mode, asking for the angle opposite the side of length 8.
First: write the rearranged formula. cos(C) = (a2 + b2 − c2) / 2ab.
Then: substitute. cos(C) = (49 + 100 − 64) / 140 = 85/140 ≈ 0.6071.
Next: apply arccosine. C = cos−1(0.6071) ≈ 52.6168°.
Answer: C ≈ 52.62°, an acute angle, consistent with the shortest side sitting opposite it.
Worked Example: The Right-Triangle Special Case
Take a = 3, b = 4, and included angle C = 90°.
First: cos(90°) = 0, so the correction term 2ab·cos(C) vanishes entirely.
Then: c2 = 9 + 16 − 0 = 25.
Next: c = √25 = 5.
Answer: c = 5, the familiar 3-4-5 triangle. This example doubles as a quick check that you entered the angle in degrees: in radian mode 90 would mean something wildly different.
Worked Example: An Obtuse Included Angle
Take a = 5, b = 6, and included angle C = 120°.
First: cos(120°) = −0.5, so the correction term becomes −2(5)(6)(−0.5) = +30.
Then: c2 = 25 + 36 + 30 = 91.
Next: c = √91 ≈ 9.5394.
Answer: c ≈ 9.5394, longer than either known side, exactly as an obtuse included angle demands.
The Triangle Inequality Guard
No formula can rescue side lengths that cannot form a triangle. If the longest side equals or exceeds the sum of the other two, the shape collapses to a line or refuses to close, and the calculator says so plainly.
This check runs before any trigonometry in SSS mode. When you see the rejection message, recheck your measurements: a typo in one digit is the usual culprit, not a failure of geometry.
Degrees Versus Radians: Getting It Right
This calculator speaks degrees end to end: you type degrees, it answers degrees. Most student errors with the law of cosines trace back to a calculator sitting in radian mode, which silently evaluates cos(60) as cos(60 radians) and produces garbage.
If an answer looks absurd, perhaps a side longer than the sum of the other two, check your angle units first. As a rule of thumb, included angles in real problems almost always arrive in degrees.
Common Law of Cosines Mistakes
The number-one mistake is using a non-included angle in SAS mode. The formula only works when the angle sits between the two known sides; any other angle needs the law of sines. The number-two mistake is forgetting to take the square root at the end, reporting c2 as if it were c.
In SSS mode, students often solve for the wrong angle by mislabeling which side is c. Remember: the angle you get is always opposite the third side you entered. Label your triangle on paper before typing.
Where the Law of Cosines Is Useful
Surveyors use it to find distances across obstacles they cannot cross, measuring two sides and the angle between them. Navigators use it to compute the third leg of a course. Engineers apply it to truss analysis, and game developers use it constantly for distance and angle math in 2D and 3D space.
In the classroom it is the bridge between right-triangle trigonometry and general triangle solving, usually taught right after the Pythagorean theorem and right before the law of sines.
It also appears in less obvious places. GPS receivers solve for position using distances that form triangles with known angles, and robotics arms compute joint angles from link lengths. Anywhere three lengths and an angle meet, the law of cosines is quietly doing the work.
How to Interpret Your Result Correctly
For a missing side, compare the answer against your two known sides: with an acute included angle the result should fall below the longer known side, and with an obtuse angle it should exceed it. For a missing angle, check that the largest angle sits opposite the longest side.
Then verify with the perimeter row and the angle classification. If anything feels off, walk the steps panel line by line; the substitution step is where mislabeled sides reveal themselves.
A final habit worth building: sketch the triangle roughly to scale and eyeball whether your answer fits the drawing. Human intuition for triangle shapes is surprisingly good, and a ten-second sketch catches more errors than any amount of re-reading formulas.
Frequently Asked Questions
1. What is the law of cosines?
It is the formula c2 = a2 + b2 − 2ab·cos(C) relating the three sides of any triangle to the cosine of one angle. It generalizes the Pythagorean theorem to triangles without a right angle.
2. When should I use the law of cosines instead of the law of sines?
Use the law of cosines when you know two sides and the included angle (SAS) or all three sides (SSS). Use the law of sines when you know angles and a side, or two sides with a non-included angle.
3. Which angle is the “included” angle?
The angle physically between your two known sides, at the vertex where they meet. If you know sides a and b, the included angle is the one at their shared endpoint, conventionally labeled C.
4. Can the law of cosines find all three angles?
Yes, by applying the SSS mode three times, once per side as the target. Find the largest angle first, since it is opposite the longest side, then subtract from 180° as you go.
5. Why did my answer come out as c squared?
You stopped one step early: the formula yields c2, and the side length is its square root. The calculator takes the root automatically, so compare your hand work against its steps panel.
6. What if my three sides cannot form a triangle?
The calculator rejects them with an explanation. Check the triangle inequality yourself: the longest side must be strictly less than the sum of the other two, or no triangle exists.
7. Does the calculator use degrees or radians?
Degrees throughout. Enter the included angle in degrees and read the resulting angle in degrees. If you have radians, multiply by 180/π first.
8. How is this related to the Pythagorean theorem?
The Pythagorean theorem is the special case where the included angle is 90°. Then cos(C) = 0, the correction term disappears, and c2 = a2 + b2 remains.
9. Can I use it on a right triangle?
Absolutely, though it is overkill. With a 90° angle the formula collapses to Pythagoras, as the worked example above demonstrates with the 3-4-5 triangle.
10. Why is my obtuse-angle side longer than both known sides?
Because cos(C) is negative for obtuse angles, turning the minus correction into a plus. The opposite side of an obtuse angle is always the longest side of the triangle.
11. What units should the sides be in?
Any length unit, as long as all three sides share it. The answer comes back in the same unit: meters in, meters out.
12. How accurate is the angle result?
The calculator reports four decimal places, far beyond what hand-drawn or measured triangles need. Near 0° or 180° the arccosine is sensitive, so treat extreme angles with appropriate caution.
13. Can the law of cosines handle the ambiguous case?
The ambiguous case belongs to SSA configurations and the law of sines. The law of cosines never produces ambiguity: SAS and SSS each determine exactly one triangle.
14. What is the 2ab·cos(C) term doing?
It corrects the Pythagorean sum for the angle’s deviation from 90°. Acute angles shorten the opposite side, obtuse angles lengthen it, and right angles leave it untouched.
15. How do I double-check my answer?
Verify the triangle inequality, confirm the largest angle opposes the longest side, and recompute with the sides relabeled. If all three checks pass, the answer is solid.