Law of Cosines Calculator

Solve oblique and right triangles instantly by entering side lengths (SSS) or two sides and their included angle (SAS).

Results are calculated automatically as you enter data.

Formula and interpretation
Triangle Status Enter the required values.
Side a
Side b
Side c
Angle A
Angle B
Angle C

▼ See explanations and tips below ▼

What Is the Law of Cosines?

The Law of Cosines is a rule that connects the three side lengths of a triangle with one of its interior angles. It works in ordinary Euclidean geometry, including triangles that are not right triangles.

For a triangle with side lengths \(a\), \(b\), and \(c\), and opposite angles \(A\), \(B\), and \(C\), the Law of Cosines helps answer two common questions:

  • If two sides and the included angle are known, what is the missing side?
  • If all three sides are known, what are the missing angles?

This makes the Law of Cosines especially useful for SSS cases, where all three sides are known, and SAS cases, where two sides and the angle between them are known.

The Law of Cosines can also be seen as a wider version of the Pythagorean theorem. When the included angle is \(90^\circ\), the cosine term becomes zero, so the formula reduces to the familiar right-triangle relationship.


Why the Law of Cosines Matters

Many triangles in real life are not right triangles. A route may change direction, a surveyor may know two distances and the angle between them, or a geometry problem may give all three side lengths without giving any angle.

The Law of Cosines gives a direct way to solve those triangles without first forcing them into right-triangle form. It is commonly useful in:

  • geometry and trigonometry homework,
  • surveying and map problems,
  • navigation and distance problems,
  • design and construction sketches,
  • checking whether a set of side lengths can form a triangle.

Key Terms to Know

  • Side \(a\), \(b\), and \(c\): The three side lengths of a triangle.
  • Angle \(A\), \(B\), and \(C\): The interior angles opposite sides \(a\), \(b\), and \(c\).
  • Opposite side: The side across from a given angle. For example, side \(a\) is opposite angle \(A\).
  • Included angle: The angle between two known sides. In SAS problems, this detail is essential.
  • SSS: A triangle-solving case where all three side lengths are known.
  • SAS: A triangle-solving case where two side lengths and the included angle are known.
  • Inverse cosine: The operation used to find an angle when its cosine value is known.
  • Triangle inequality: The rule that the sum of any two side lengths must be greater than the third side for a non-degenerate triangle.

How the Law of Cosines Works

The Law of Cosines has three equivalent forms, one for each side of the triangle:

$$ a^2 = b^2 + c^2 - 2bc\cos(A) $$
$$ b^2 = a^2 + c^2 - 2ac\cos(B) $$
$$ c^2 = a^2 + b^2 - 2ab\cos(C) $$

The pattern is the same each time: the square of one side equals the sum of the squares of the other two sides, minus twice the product of those sides and the cosine of the included angle.

If you know two sides and the included angle, solve for the missing side. For example, if you know \(a\), \(b\), and \(C\), then:

$$ c = \sqrt{a^2 + b^2 - 2ab\cos(C)} $$

If you know all three sides, rearrange the formula to solve for an angle. For angle \(C\):

$$ C = \cos^{-1}\left(\frac{a^2 + b^2 - c^2}{2ab}\right) $$

After two angles are known, the third angle can be found from the angle-sum rule:

$$ A + B + C = 180^\circ $$

SSS and SAS: Which Case Are You Solving?

Use SSS when you know all three side lengths. In that case, use the angle form of the Law of Cosines to find missing angles.

Use SAS when you know two sides and the angle between them. In that case, use the side form of the Law of Cosines first, then find the remaining angles.

The word "included" is important. If the known angle is not between the two known sides, the situation is SSA, not SAS, and it can be ambiguous. This calculator is designed for SSS and SAS, not SSA.


Examples of the Law of Cosines in Practice

Example 1: Finding a Missing Side from Two Sides and the Included Angle

Suppose a triangle has:

  • \(a = 5\)
  • \(b = 7\)
  • \(C = 45^\circ\)

Because angle \(C\) is between sides \(a\) and \(b\), use:

$$ c = \sqrt{a^2 + b^2 - 2ab\cos(C)} $$

Substitute the known values:

$$ c = \sqrt{5^2 + 7^2 - 2(5)(7)\cos(45^\circ)} $$
$$ c = \sqrt{25 + 49 - 70\cos(45^\circ)} $$

Since \(\cos(45^\circ) \approx 0.7071\):

$$ c \approx \sqrt{74 - 49.4975} $$
$$ c \approx \sqrt{24.5025} $$
$$ c \approx 4.95 $$

So the missing side is approximately \(4.95\) in the same unit used for the side inputs. The remaining angles are approximately \(45.582^\circ\) and \(89.418^\circ\).


Example 2: Finding Angles from Three Sides

Suppose a triangle has side lengths:

  • \(a = 7\)
  • \(b = 8\)
  • \(c = 9\)

To find angle \(A\), use:

$$ A = \cos^{-1}\left(\frac{b^2 + c^2 - a^2}{2bc}\right) $$

Substitute the known values:

$$ A = \cos^{-1}\left(\frac{8^2 + 9^2 - 7^2}{2(8)(9)}\right) $$
$$ A = \cos^{-1}\left(\frac{64 + 81 - 49}{144}\right) $$
$$ A = \cos^{-1}\left(\frac{96}{144}\right) $$
$$ A \approx 48.19^\circ $$

Using the same method:

$$ B \approx 58.41^\circ $$

Then use the angle-sum rule:

$$ C = 180^\circ - A - B $$
$$ C \approx 180^\circ - 48.19^\circ - 58.41^\circ $$
$$ C \approx 73.40^\circ $$

The solved triangle has angles of approximately \(48.19^\circ\), \(58.41^\circ\), and \(73.40^\circ\).


Example 3: A Common Edge Case with Invalid Side Lengths

The side lengths \(2\), \(3\), and \(5\) may look close to a triangle, but they do not form a non-degenerate triangle because:

$$ 2 + 3 = 5 $$

For a valid triangle, the sum of any two sides must be greater than the third side, not merely equal to it. When equality occurs, the "triangle" collapses into a straight line, so it is rejected as invalid.


How to Interpret the Result

A solved result means the inputs describe a valid Euclidean triangle and the missing side or angles were computed successfully.

Side results use the same unit as the side inputs. If the sides were entered in centimeters, the side result is in centimeters. If the sides were entered in inches, the side result is in inches. The calculator does not convert units, so all side lengths must be entered in one consistent unit.

Angle results are interior triangle angles measured in degrees. A result such as \(73.4^\circ\) means the angle inside the triangle at that vertex is about \(73.4\) degrees.

The displayed side and angle values are rounded for readability. Main result fields show up to 3 decimal places, while calculation steps may show more detail. If a result is very small, it may be shown in exponential notation.

The diagram is a proportional drawing, not an absolute-scale blueprint. It is useful for checking the relative shape, side labels, and angle labels, but the size on the screen is scaled to fit the display.

If the status says Valid Triangle, the inputs passed the required checks and produced finite side and angle values. If it says Enter Parameters, at least one required input for the selected mode is blank. If it says Invalid Parameters, the inputs failed a validation rule, such as a non-positive side length, an invalid angle, or a triangle inequality failure.


Common Mistakes and Misconceptions

Using the wrong angle in an SAS problem. The Law of Cosines needs the included angle between the two known sides. If you use an angle that is not between those sides, the result will not match the intended triangle.

Mixing units. Do not enter one side in inches and another side in centimeters unless you first convert them to the same unit.

Entering radians instead of degrees. Angle inputs are in degrees. For example, enter \(60\) for \(60^\circ\), not \(\frac{\pi}{3}\).

Trying to solve an unsupported case. SSS and SAS work well with the Law of Cosines. SSA, ASA, AAS, AAA, coordinate-geometry cases, and right-triangle-only cases are different setups and are not handled by this calculator.

Ignoring the triangle inequality. Three positive numbers do not always form a triangle. The longest side must be shorter than the sum of the other two sides.

Misreading the side and angle labels. Side \(a\) is opposite angle \(A\), side \(b\) is opposite angle \(B\), and side \(c\) is opposite angle \(C\).

Rounding too early. If you are working by hand, keep several decimal places during intermediate steps. Rounding early can noticeably affect the final angle values.

Treating the drawing as exact scale. The diagram is scaled to fit the canvas. It shows the triangle shape proportionally, but it is not meant to preserve a real-world drawing scale.


When to Use the Law of Cosines

Use the Law of Cosines when:

  • all three side lengths of a triangle are known and you need the angles;
  • two side lengths and the included angle are known and you need the third side;
  • the triangle is not necessarily a right triangle;
  • you need a bridge between the Pythagorean theorem and general triangle solving;
  • you need to check whether side lengths and angles describe a possible triangle.

If the triangle is a right triangle and the unknown value only involves the two legs and hypotenuse, the Pythagorean theorem may be simpler. If the known values form ASA, AAS, or SSA, a Law of Sines method may be more appropriate.


Limitations and Things to Keep in Mind

This calculator assumes ordinary Euclidean triangle geometry, where the interior angles of a triangle add to \(180^\circ\). It is not designed for spherical or geodesic triangles, such as very large navigation problems on the surface of Earth.

Only SSS and SAS modes are supported. The calculator does not solve SSA, ASA, AAS, AAA, coordinate-geometry, or right-triangle-only cases.

Side lengths must be positive finite numbers greater than zero. Zero, negative values, non-numeric text, infinity, and blank required fields are not valid side inputs.

Although positive finite side inputs are accepted, an SAS calculation is rejected when a scale-safe check finds its unrounded derived side below the smallest positive JavaScript number (about \(4.94 \times 10^{-324}\)). A result exactly at that minimum remains supported; below it cannot be represented. Use a larger common unit or scale every side length up by the same factor.

Angle inputs must be greater than \(0^\circ\) and less than \(180^\circ\). Angles equal to \(0^\circ\), equal to \(180^\circ\), or greater than \(180^\circ\) do not form a supported triangle in this calculator.

All side lengths must use the same unit. The calculator treats side inputs as unitless numbers in a shared unit and does not perform unit conversion.

Degenerate triangles are not supported. In SSS mode, the triangle inequality must be strict: the sum of any two sides must be greater than the third side.

Displayed results are rounded, so small differences can appear when comparing by-hand work, step-by-step values, and final output fields. For schoolwork, engineering sketches, safety-related work, construction, surveying, or other high-stakes decisions, double-check the setup and consult a qualified professional when accuracy matters.


How to Use This Calculator

  1. Choose the mode that matches the information you know.
  2. Enter positive side lengths using the same unit for every side.
  3. If using an SAS mode, enter the included angle in degrees.
  4. Review the status message to confirm whether the inputs form a valid triangle.
  5. Read the solved side and angle values.
  6. Use the calculation steps to see how the Law of Cosines and angle-sum rule were applied.
  7. Use the diagram as a proportional visual check of the side and angle labels.
  8. If a diagram download control is available, use it to save the current triangle image as a PNG.
Mode Use this when you know What the included angle means
SSS \(a\), \(b\), and \(c\) No angle is entered; the angles are solved from the sides.
SAS_C \(a\), \(b\), and \(C\) Angle \(C\) is between sides \(a\) and \(b\).
SAS_A \(b\), \(c\), and \(A\) Angle \(A\) is between sides \(b\) and \(c\).
SAS_B \(a\), \(c\), and \(B\) Angle \(B\) is between sides \(a\) and \(c\).

Frequently Asked Questions

Is the Law of Cosines the same as the Pythagorean theorem?

No. The Pythagorean theorem applies directly to right triangles, while the Law of Cosines applies to general Euclidean triangles. When the included angle is \(90^\circ\), the Law of Cosines simplifies to the Pythagorean theorem.


Why does the SAS angle have to be the included angle?

The cosine term uses the angle between the two known sides. If the angle is not between those sides, the measurements describe a different triangle-solving case, often SSA. SSA can be ambiguous, so it is not the same as SAS.


Can this calculator solve any triangle?

No. It supports SSS and three SAS variants. It does not solve SSA, ASA, AAS, AAA, coordinate-geometry cases, or right-triangle-only setups.


What units should I use for side lengths?

You can use any length unit, but every side must use the same unit. If you enter sides in meters, the solved side is in meters. If you enter sides in feet, the solved side is in feet.


Can I enter decimals or scientific notation?

Yes, positive decimal values are supported, and positive scientific notation can be used for side lengths. Required side values must still be greater than zero, and angle values must be greater than \(0^\circ\) and less than \(180^\circ\).


Why did I get an invalid result?

An invalid result usually means at least one input failed a rule. Common causes include a zero or negative side, an angle outside the allowed range, a side set that violates the triangle inequality, mixed-up SAS inputs, or non-numeric text in a required field.


Sources and References

Books

  1. Jay Abramson. Algebra and Trigonometry 2e. OpenStax, 2021. Section 10.2, “Non-right Triangles: Law of Cosines.” https://openstax.org/books/algebra-and-trigonometry-2e/pages/10-2-non-right-triangles-law-of-cosines
  2. Jay Abramson. Precalculus 2e. OpenStax, 2021. Section 8.2, “Non-right Triangles: Law of Cosines.” https://openstax.org/books/precalculus-2e/pages/8-2-non-right-triangles-law-of-cosines
  3. Donna Kirk. Contemporary Mathematics. OpenStax, 2023. Section 10.3, “Triangles.” https://openstax.org/books/contemporary-mathematics/pages/10-3-triangles

Online and Official Sources

  1. Eric W. Weisstein. “Triangle Inequality.” Wolfram MathWorld. Accessed June 29, 2026. https://mathworld.wolfram.com/TriangleInequality.html