The law of cosines calculator solves a triangle in the two situations where the law of sines cannot get started: when you know all three sides (SSS) and when you know two sides with the angle sitting between them (SAS). It returns every remaining angle, the missing side where there is one, and the area — and before any of that it checks whether the numbers you entered can form a triangle at all.
Arb Digital maintains this alongside a set of geometry tools that each do one job properly. It is worth naming the boundary early: the triangle area calculator finds area from base and height, from three sides via Heron's formula, or from the SAS case, and the Pythagorean theorem calculator handles right triangles specifically. This page does something different — it solves the triangle, producing the unknown angles and sides rather than a single area figure.
What This Law of Cosines Calculator Does
Choose SSS and enter three side lengths, and the calculator returns all three interior angles plus the area. Choose SAS and enter two sides with the angle between them, and it returns the third side first, then the two remaining angles and the area. Either way you get a complete triangle from a partial description, which is what "solving a triangle" means.
The validation is not decoration. In SSS mode, a set of three lengths only closes into a triangle if every side is strictly shorter than the sum of the other two. Enter 2, 3 and 9 and no triangle exists — the two short sides cannot reach across the long one. Many calculators quietly hand back an arccosine of an out-of-range number and print NaN or an error code. This one explains which inequality failed, in words.
How to Use It
- Pick your case. SSS if you have three side lengths. SAS if you have two sides and the angle enclosed by them.
- Enter the sides. Sides a and b are always used. Side c is used in SSS mode and calculated in SAS mode.
- Enter the included angle if you are in SAS mode. It must lie strictly between 0° and 180°, since a triangle's interior angle cannot reach either limit.
- Choose degrees or radians. Every angle in and out of the calculator uses the unit you select here.
- Read the whole panel. The hero shows angle C, the grid shows angles A and B, side c, and the area, so you can check the three angles sum to 180°.
The Formula: How It's Calculated
The law of cosines is a single identity written three ways, one for each vertex:
c2 = a2 + b2 − 2ab·cos C, and equivalently a2 = b2 + c2 − 2bc·cos A and b2 = a2 + c2 − 2ac·cos B. Each version relates one side to the two sides that meet at the angle opposite it.
For SAS the formula is used forwards: substitute a, b and C, and take the square root to get c. For SSS it is rearranged to isolate the cosine, giving cos C = (a2 + b2 − c2) ÷ 2ab, and the angle follows from an inverse cosine. Working the example loaded above, with a = 7, b = 8 and c = 9: cos C = (49 + 64 − 81) ÷ (2 × 7 × 8) = 32 ÷ 112 = 0.285714, so C = 73.398°. Repeating for A gives cos A = (64 + 81 − 49) ÷ 144 = 0.666667 and A = 48.190°, which leaves B = 180 − 73.398 − 48.190 = 58.412°. The Wolfram MathWorld entry on the law of cosines derives the identity from first principles.
The Triangle Inequality: Why Some Side Sets Have No Answer
Three positive numbers do not automatically describe a triangle. The requirement, called the triangle inequality, is that a + b > c, a + c > b, and b + c > a — every side must be strictly shorter than the sum of the other two. Physically it is obvious: lay the longest stick down, and the other two must be long enough together to bridge its ends and still meet above it.
What makes this worth handling explicitly is how the failure shows up in the algebra. If c is too long, the expression (a2 + b2 − c2) ÷ 2ab drops below −1, and inverse cosine has no real output below −1 — the same domain restriction explained on our arccos calculator. So the algebra does not fail loudly; it fails as a domain error, which many implementations render as NaN. The boundary case is worth knowing too: when a + b equals c exactly, the "triangle" flattens into a straight line with zero area, called a degenerate triangle. This calculator rejects that as well, because a line segment is not a triangle even though the arithmetic tolerates it.
Why the Law of Cosines Generalises Pythagoras
Set C = 90°. Then cos C = 0, the entire −2ab·cos C term vanishes, and the formula collapses to c2 = a2 + b2 — the Pythagorean theorem exactly. The law of cosines is therefore not a separate rule to memorise; it is Pythagoras with a correction term that measures how far the triangle deviates from having a right angle.
That reading also tells you the sign of the correction without any calculation. If C is acute, cos C is positive, the correction subtracts, and c comes out shorter than the Pythagorean prediction. If C is obtuse, cos C is negative, the correction adds, and c comes out longer. So a quick sanity check on any SAS result is to compute √(a2 + b2) mentally and see whether your answer falls on the correct side of it. With a = 5, b = 7 and C = 60°, Pythagoras would predict 8.602; the true answer is 6.245, correctly shorter because 60° is acute.
Law of Cosines or Law of Sines? A Clean Decision Rule
The rule is short. Use the law of cosines when the known angle sits between the known sides (SAS), or when you know no angles at all (SSS). Use the law of sines calculator when you have an angle and the side opposite it as a matched pair — the AAS, ASA and SSA cases.
There is a second, subtler reason to prefer the law of cosines when you can. It never produces an ambiguous answer. Inverse cosine returns a unique angle between 0° and 180°, which is precisely the range an interior angle can occupy, so every SSS solve has exactly one solution. The law of sines relies on inverse sine, whose range stops at 90°, which is what opens the door to the ambiguous SSA case where two different triangles fit the same data. Where both laws apply, the cosine route is the safer one.
Rounding, Precision, and the Largest-Angle-First Habit
A practical habit from surveying and navigation: when solving SSS, compute the angle opposite the longest side first. That angle is the only one that could possibly be obtuse — a triangle can have at most one — so finding it first tells you immediately whether the triangle is acute, right or obtuse, and it avoids a classic trap. If you find the two smaller angles first and subtract from 180°, any rounding error in both propagates straight into the third. Computing the large angle directly and subtracting for one small angle keeps the error confined.
On precision generally: intermediate values here involve squares and square roots, so rounding early costs more than usual. Squaring a length rounded to three significant figures roughly doubles its relative error before you have even reached the division. Carry full precision through and round once at the end. If you need to move between angle units at any stage, our angle converter handles degrees, radians and gradians, and the trigonometric functions calculator will evaluate any individual cosine you want to check by hand.
Where This Turns Up Outside a Textbook
The SSS case is the workhorse of any situation where distances are easy to measure and angles are not. Give a surveyor three measured distances between three markers and the law of cosines returns the angles of the plot without a theodolite. In navigation, the same identity in its spherical form underlies great-circle distance between two points on the Earth. In computer graphics and robotics, the angle between two vectors — the basis of lighting calculations and inverse kinematics — is the SSS case in disguise, with the third side being the distance between the vector tips.
Structural work uses the SAS case constantly: two members of known length meeting at a known joint angle, and the question is how far apart their free ends are. That is c2 = a2 + b2 − 2ab·cos C and nothing more. The NIST Digital Library of Mathematical Functions gives the underlying trigonometric definitions in their standard reference form.
Arb Digital publishes hundreds of free tools across maths, geometry, finance and conversion. No sign-up, no limits, nothing stored.
Browse All Free Tools Contact Arb DigitalCommon Mistakes to Avoid
- Using an angle that is not between the two sides — SAS means the angle is enclosed by sides a and b. If it is opposite one of them, you need the law of sines instead.
- Forgetting the square root — the formula gives c2, not c. It is the single most common slip in SAS problems.
- Dropping the minus sign on an obtuse cosine — cos 120° is −0.5, and losing that sign turns a subtraction into an addition and shrinks the answer.
- Accepting three sides without checking the inequality — 2, 3 and 9 produce a domain error, not a triangle.
- Rounding before squaring — squaring roughly doubles the relative error already present in a rounded length.
Related Free Tools From Arb Digital
Solve the AAS, ASA and SSA cases with the law of sines calculator, get area on its own from the triangle area calculator, handle right triangles with the Pythagorean theorem calculator, and check individual function values on the trigonometric functions calculator. For the inverse cosine step on its own, use the arccos calculator, or browse the full free online tools hub.
Frequently Asked Questions
Use the law of cosines when you know three sides (SSS) or two sides and the angle between them (SAS). Use the law of sines when you have a matched pair — an angle together with the side opposite it — which covers AAS, ASA and SSA.
c2 = a2 + b2 − 2ab·cos C, where C is the angle between sides a and b. Rearranged to find an angle from three sides it becomes cos C = (a2 + b2 − c2) ÷ 2ab.
Your three sides violate the triangle inequality. Every side must be strictly shorter than the sum of the other two. If one side equals or exceeds that sum, the shape cannot close, and the cosine calculation falls outside the valid range of −1 to 1.
Yes — it is a generalisation. When the angle is 90°, its cosine is zero, the correction term disappears, and the formula reduces exactly to c2 = a2 + b2.
No. Inverse cosine returns a single angle between 0° and 180°, which is the full range an interior angle can take, so an SSS or SAS solve always has exactly one solution. The ambiguity in the SSA case comes from inverse sine, not inverse cosine.
The one opposite the longest side. It is the only angle that can be obtuse, so finding it first identifies the triangle type immediately and limits how far rounding error can spread through the remaining angles.
Yes. Switch the angle unit selector to radians and both the included angle you enter and every angle returned will use radians instead of degrees.
This tool is provided for education and reference. Verify any result used in construction, surveying or engineering work against an independent calculation.