Law of Cosines Calculator
Enter your values
Enter your values and press Calculate — your answer, visual and step-by-step solution appear here.
What Is the Law of Cosines?
The law of cosines says that in any triangle, the square of one side equals the sum of the squares of the other two sides minus twice their product times the cosine of the angle between them. In symbols, with sides a, b, c and the angle C opposite side c:
Here side c sits opposite angle C, and C is the included angle — the angle formed between sides a and b. Unlike the Pythagorean theorem, this rule works for any triangle, not just right triangles, which makes it the go-to tool for oblique (non-right) triangles. This free law of cosines calculator applies the formula for you and shows every step. Need other tools? See all our free math calculators.
The Law of Cosines Formulas (All Three Sides + the Angle Form)
Because the labels a, b, and c are interchangeable, the law of cosines comes in three matching versions — one for each side paired with its opposite angle. Use the side form when you know two sides and the included angle (SAS):
b² = a² + c² − 2ac·cos B
c² = a² + b² − 2ab·cos C
When you already know all three sides and want to solve for an angle (the SSS workhorse), rearrange each formula to isolate the cosine:
cos B = (a² + c² − b²) / (2ac)
cos C = (a² + b² − c²) / (2ab)
After computing the cosine, take the inverse cosine (arccos) of the result to recover the angle in degrees. The calculator's two modes mirror these exactly: the SAS mode uses the side form to find a missing side, and the SSS mode uses the angle form to find every angle. If you ever need a raw trig value on its own, the trig functions calculator evaluates sine, cosine, and tangent directly.
When to Use the Law of Cosines (vs. Law of Sines vs. Pythagoras)
The hardest part is usually deciding which rule fits your triangle. Match what you already know to the right method:
| You know | Use | Why |
|---|---|---|
| 2 sides + included angle (SAS) | Law of cosines | Directly gives the third side |
| 3 sides (SSS) | Law of cosines | Gives any angle via the angle form |
| 2 angles + a side (ASA / AAS) | Law of sines | Pairs each side with its opposite angle |
| 2 sides + a non-included angle (SSA) | Law of sines (ambiguous case) | May yield 0, 1, or 2 triangles |
| A right triangle | Pythagorean theorem | Special case where cos 90° = 0 |
The bridge to the law of sines is simple: if your known angle is not tucked between your two known sides, the law of cosines can't start cleanly, so you switch to the law of sines instead. The bridge to Pythagoras is even neater — a right triangle is just the law of cosines with a 90° angle, where the cosine term vanishes (covered below). For a step-by-step walk-through of the decision, see Law of Sines vs. Law of Cosines: when to use each.
How to Use This Law of Cosines Calculator
- Choose your mode. Pick SAS if you have two sides and the angle between them, or SSS if you have all three side lengths.
- Enter the known values. Type your two sides and included angle (SAS) or your three sides (SSS). Tap an example chip — such as 8, 5, 60° or 3, 4, 90° — for an instant demo.
- Press Calculate. A built-in triangle-inequality check first confirms your inputs can actually form a triangle and flags impossible ones.
- Read the results. The grid lists all three angles and sides, plus a sense-check (it verifies the longest side sits opposite the largest angle and classifies the triangle) and a to-scale diagram.
- Open Step-by-Step. Expand the Steps tab to see the full derivation worked line by line for either mode.
Worked Examples (Step by Step)
These two examples mirror exactly what the calculator produces — one for each mode.
SAS — find the third side
Given two sides and the angle between them: a = 8, b = 5, included angle C = 60°. Find side c.
- Write the side form. c² = a² + b² − 2ab·cos C.
- Substitute the values. c² = 8² + 5² − 2·8·5·cos 60°.
- Simplify. Since cos 60° = 0.5, this is c² = 64 + 25 − 80(0.5) = 89 − 40 = 49.
- Take the square root. c = √49 = 7.
SSS — find an angle from three sides
Given all three sides: a = 5, b = 7, c = 8. Find the angle C opposite the longest side.
- Write the angle form. cos C = (a² + b² − c²) / (2ab).
- Substitute the values. cos C = (5² + 7² − 8²) / (2·5·7) = (25 + 49 − 64) / 70.
- Simplify the fraction. cos C = 10 / 70 ≈ 0.1429.
- Take the inverse cosine. C = arccos(0.1429) ≈ 81.79°.
An applied example
Two trails leave the same trailhead at an angle of 60° between them; one runs 8 km and the other 5 km. How far apart are their endpoints in a straight line? This is the SAS case above, so the gap is c = 7 km. The same calculation finds the straight-line distance across a lake or the separation between two flight paths.
How the Law of Cosines Generalizes the Pythagorean Theorem
The Pythagorean theorem is simply the law of cosines for a right triangle. When the included angle C = 90°, its cosine is zero (cos 90° = 0), so the final term disappears entirely:
That is the familiar Pythagorean theorem, a² + b² = c². In other words, the law of cosines is the more general rule, and Pythagoras is the special case it collapses to at 90°. The calculator's sense-check confirms this: feed it a right triangle and it flags the right angle and notes that Pythagoras would give the same answer. This relationship appears in any standard trigonometry or precalculus textbook.
Real-World Uses of the Law of Cosines
- Surveying & land measurement. When a distance can't be measured directly — across a lake or a ravine — surveyors measure two accessible sides and the angle between them, then use the law of cosines (SAS) to compute the gap. This is the core idea behind triangulation.
- Navigation & flight paths. Given two bearings from a common point and the distances along each, the law of cosines finds the straight-line separation between the endpoints, helping pilots and sailors plan or correct a course.
- Engineering & trusses. Non-right triangular frames are everywhere in bridges and roofs. The law of cosines finds an unknown member length from two known members and their joint angle, or recovers a joint angle from three known lengths.
- Game development, graphics & robotics. The angle between two vectors comes straight from the law of cosines — the dot-product formula is the same identity — which drives lighting, collision angles, and robot-arm link geometry.
The Ambiguous Case and Why This Calculator Uses SAS & SSS
SAS and SSS each lock in exactly one triangle, so the answer is always unique — that is why this tool is built around those two inputs. The trouble spot is SSA (two sides and a non-included angle), known as the ambiguous case: depending on the numbers it can produce zero, one, or two valid triangles. Because the answer isn't unique, the law of cosines (and this calculator) deliberately stays with the unambiguous SAS and SSS cases.
Common Mistakes
As an Amazon Associate, MathInSite earns from qualifying purchases.
Frequently Asked Questions
-
What is the law of cosines formula?
The law of cosines is c² = a² + b² − 2ab·cos C, where a, b, and c are the triangle's sides and C is the angle opposite side c. By relabeling, the same rule gives a² and b² too. It works for any triangle.
-
When should I use the law of cosines?
Use it when you know two sides and the included angle (SAS) to find the third side, or when you know all three sides (SSS) to find any angle. For two angles and a side, or a non-included angle, use the law of sines instead.
-
How do I find an angle using the law of cosines?
Use the angle form: cos C = (a² + b² − c²) / (2ab). Compute the fraction, then take the inverse cosine (arccos) of the result to get angle C in degrees. Repeat with relabeled sides for the other angles.
-
What is the difference between SAS and SSS?
SAS means you know two Sides and the included Angle between them; you use the side form to find the missing side. SSS means you know all three Sides; you use the angle form to find each angle. Both define exactly one triangle.
-
Law of cosines vs. law of sines — which do I use?
Use the law of cosines for SAS and SSS, where a side or angle is sandwiched by known values. Use the law of sines for ASA, AAS, and the ambiguous SSA case, where each side pairs neatly with its opposite angle.
-
How is the law of cosines related to the Pythagorean theorem?
The Pythagorean theorem is the law of cosines for a right triangle. When angle C = 90°, cos 90° = 0, so c² = a² + b² − 2ab·(0) reduces to a² + b² = c². Pythagoras is just the special 90° case.
-
Why must the angle be the "included" angle?
The formula c² = a² + b² − 2ab·cos C only holds when C is the angle between sides a and b (opposite c). That geometric relationship is what links the three sides; an angle in any other position breaks the identity, so the law of sines applies there.
-
Why did the calculator say my triangle is invalid?
By the triangle inequality, every side must be shorter than the sum of the other two. If your three sides fail this (like 2, 3, 10), no real triangle exists, the cosine works out beyond ±1, and arccos has no solution — so the calculator flags the input.