Law of Cosines Calculator - SAS Triangle Side and Angle Solver

Use this law of cosines calculator to find the third side, the other two angles, the area, and the perimeter from any two sides and the included angle.

Updated: June 16, 2026 • Free Tool

Law of Cosines Calculator

First known side length in any consistent length unit (cm, m, in, ft, ...).

Second known side length in the same unit you used for side a.

Angle between sides a and b, in degrees. Use 0 < C < 180 for a non-degenerate triangle.

Results

Side c (opposite C)
0units
Angle A 0degrees
Angle B 0degrees
Triangle area 0sq units
Triangle perimeter 0units

What Is the Law of Cosines Calculator?

A law of cosines calculator is a tool that solves for the missing side of a triangle when you know two sides and the angle between them, then keeps going to give you the other two angles, the area, and the perimeter from the same numbers.

  • Survey a triangular lot: Walking two sides of a plot and measuring the angle between them is often easier than measuring the third side directly, especially when the third side crosses rough terrain.
  • Resolve forces or vectors: Engineers and physics students use the same identity to combine two forces that meet at a known angle into one resultant vector.
  • Check SAS homework problems: Students can compare their hand-computed side c, other angles, and area against a known result.

The classic problem this calculator answers is the SAS case: two known sides, the included angle, and the third side as the answer. Once c is in hand, the rest follows from the law of sines and the area and perimeter formulas. The same identity covers acute, right, and obtuse triangles, since the law of cosines does not need a right angle like the Pythagorean theorem does.

Once you have the third side, a Triangle Area Calculator can take you further with the base-and-height, three-sides, and SAS area modes.

How the Law of Cosines Calculator Works

Behind the panel sits one identity, rearranged once to find a side and again to find an angle, plus the standard follow-up formulas for angles, area, and perimeter.

c^2 = a^2 + b^2 - 2ab * cos(C)
  • a: First known side length. Use any consistent length unit.
  • b: Second known side length. Must use the same length unit as side a.
  • C: Included angle between sides a and b, measured in degrees. The formula also works with radians if you convert C first.
  • c: Side opposite the included angle. This is the value the calculator returns for the SAS case.

The first step is converting the included angle from degrees to radians because the JavaScript Math.cos function expects radians. Multiplying by pi and dividing by 180 makes that conversion exact, and the square root of a clamped radicand stays safe near the degenerate limits of a 0 or 180 degree included angle.

Once c is in hand, the law of sines gives the other two angles, the area is one-half times a times b times sin(C), and the perimeter is a + b + c.

Right triangle check: a=3, b=4, C=90 degrees

Side a = 3, side b = 4, included angle C = 90 degrees.

c^2 = 3^2 + 4^2 - 2*3*4*cos(90) = 9 + 16 - 0 = 25, so c = 5. A = asin(3*1/5) ≈ 36.87 degrees, B ≈ 53.13 degrees, area = 0.5*3*4*1 = 6, perimeter = 3 + 4 + 5 = 12.

Side c = 5.00 units, angle A = 36.87 degrees, angle B = 53.13 degrees, area = 6.00 sq units, perimeter = 12.00 units.

The cosine term vanishes at 90 degrees, so the law of cosines reduces to the Pythagorean theorem and the calculator matches the 3-4-5 triangle exactly.

Obtuse triangle: a=4, b=5, C=120 degrees

Side a = 4, side b = 5, included angle C = 120 degrees.

c^2 = 4^2 + 5^2 - 2*4*5*cos(120) = 16 + 25 - 40*(-0.5) = 41 + 20 = 61, so c = sqrt(61) ≈ 7.81.

Side c = 7.81 units, angle A = 26.33 degrees, angle B = 33.67 degrees, area = 8.66 sq units, perimeter = 16.81 units.

The obtuse angle grows c^2 by 2ab|cos(C)|, which makes the third side longer than the right-triangle result for the same two legs.

According to Wikipedia: Law of cosines, the law of cosines states c^2 = a^2 + b^2 - 2ab * cos(C), and the same identity rearranges to cos(C) = (a^2 + b^2 - c^2) / (2ab) when all three sides are known.

According to Britannica: Law of cosines, the law of cosines generalizes the Pythagorean theorem to any triangle by relating the side lengths to the cosine of the included angle, and it reduces to c^2 = a^2 + b^2 when the included angle is 90 degrees.

After the third side is known, the two remaining angles fall out of the law of sines, and an Arcsin Calculator can verify each one when you want a second opinion.

Key Concepts Behind the Law of Cosines

Four ideas carry the whole identity. Once you can name them, the SAS case feels mechanical.

The included angle

The angle you enter is the angle that sits between the two sides you entered, not just any angle of the triangle. Calling it the included angle keeps that convention explicit and avoids the SSA ambiguity that traps the law of sines.

SAS versus SSS cases

The SAS case (two sides and the included angle) and the SSS case (three sides) are the two situations where the law of cosines gives a direct, unambiguous answer.

Why the cosine term can be negative

The cosine of an obtuse angle is negative, so the -2ab*cos(C) term becomes a positive addition. That is why an obtuse triangle's opposite side ends up longer than a right triangle with the same two legs.

Connection to the Pythagorean theorem

Setting C = 90 degrees makes cos(C) equal zero, so the formula collapses to c^2 = a^2 + b^2. The law of cosines is the Pythagorean theorem with one extra term that turns on when the angle is not a right angle.

The same identity also works in reverse. If you start with three sides, cos(C) = (a^2 + b^2 - c^2) / (2ab), and one application of arccos gives the included angle.

When the included angle is 90 degrees, this calculator behaves like a Right Triangle Calculator and you can read the result as a Pythagorean triple in any consistent unit.

How to Use This Calculator

Six steps, from typing the first side to reading the area at the bottom of the results panel.

  1. 1 Enter side a: Type the first known side length in any consistent length unit such as centimeters, meters, inches, or feet.
  2. 2 Enter side b: Type the second side in the same unit you used for side a. Mixing units in the same triangle is the most common source of bad answers.
  3. 3 Enter the included angle C: Type the angle between sides a and b in degrees. The number must be strictly between 0 and 180 to describe a real triangle.
  4. 4 Read the missing side c: The top of the results panel shows side c, opposite the included angle C, computed from c^2 = a^2 + b^2 - 2ab*cos(C).
  5. 5 Read the other two angles: Angle A and angle B come from the law of sines using the computed side c. Their sum plus C should be 180 degrees, and small floating-point drift is normal.
  6. 6 Read the area and perimeter: Area is one-half times a times b times sin(C). Perimeter is a + b + c. Use the same length unit for both outputs that you used for the input sides.

Try a = 5, b = 7, C = 60 degrees. The panel should show c ≈ 6.245 units, A ≈ 49.10 degrees, B ≈ 70.90 degrees, area ≈ 15.16 sq units, and perimeter ≈ 18.245 units. Tweak any of the three inputs to see how the missing side and the other two angles move together.

If you have three sides instead of two, the same identity rearranges to cos(C) = (a^2 + b^2 - c^2) / (2ab) and an Arccos Calculator returns the included angle in one click.

Benefits of Using the Law of Cosines Calculator

Five practical reasons to let the panel do the work instead of doing the cosine rule by hand.

  • One identity, three answers: A single c^2 = a^2 + b^2 - 2ab*cos(C) call returns the missing side, the other two angles, the area, and the perimeter without re-entering the inputs.
  • Works on acute, right, and obtuse triangles: The same formula covers every shape, so there is no branch logic to remember when the included angle is past 90 degrees.
  • No unit conversion needed: Side a and side b can use any consistent length unit. The output area inherits the same unit squared and the perimeter the same unit as the inputs.
  • Fast sanity check for homework: Typing the three given values takes a few seconds and the panel prints all derived values at once.
  • Stable near the limits: The radicand is clamped at zero before the square root, so the calculator never returns NaN near the degenerate limits of a 0 or 180 degree included angle.

The panel also works as a teaching aid. Watching the three input fields change and seeing all five output rows update makes the relationship between sides, the included angle, and the other two angles easier to internalize than reading a textbook diagram.

When you need more than SAS, a general Triangle Calculator can chain the law of cosines and the law of sines together to handle the AAA, AAS, and ASA cases in one workflow.

Factors That Affect Your Results

Four things that move the numbers in the panel, plus two honest caveats about the underlying math.

The included angle must be between 0 and 180 degrees

Angles of 0 or 180 describe a degenerate triangle that has collapsed onto a line. Real triangles live strictly inside that range, and the calculator treats anything outside it as an error.

The two given sides must be positive

Zero or negative side lengths are not physical. The calculator surfaces a validation error so the radicand never becomes negative.

Use the same length unit on both sides

Side a and side b have to share one unit. Mixing meters with inches gives a real number, but it is the real number for the wrong triangle, and the area and perimeter inherit the same mixed unit.

Floating-point rounding

JavaScript uses double-precision floats, so the calculator is accurate to about fifteen significant digits. The panel rounds to two decimal places.

  • The current panel focuses on the SAS case, where you give two sides and the included angle. The SSS rearrangement is mentioned in the Key Concepts section.
  • The law of cosines is a purely algebraic identity, so it cannot detect a typo. Enter 60 in the included angle box when you meant 6 and the panel will happily show a c value for a 60 degree triangle.

The output assumes a non-degenerate triangle. As the included angle approaches 0 or 180, the third side c approaches a small or large limit and the area approaches zero, although the formulas still work.

As published by Wolfram MathWorld: Law of Cosines, the law of cosines generalizes the Pythagorean theorem to any triangle and accepts a, b, and C in any consistent angle unit, including degrees or radians.

When you want the area from three sides rather than from SAS, an Area of an Oblique Triangle Calculator walks you through Heron's formula in the same session.

Law of cosines calculator with two sides and included angle inputs and computed third side, the other two angles, area, and perimeter outputs
Law of cosines calculator with two sides and included angle inputs and computed third side, the other two angles, area, and perimeter outputs

Frequently Asked Questions

Q: What is the law of cosines?

A: The law of cosines is a triangle identity that generalizes the Pythagorean theorem to any triangle, not just right triangles. It states c^2 = a^2 + b^2 - 2ab*cos(C), where C is the angle between sides a and b, and c is the side opposite C.

Q: When should I use the law of cosines instead of the law of sines?

A: Use the law of cosines when you have two sides and the included angle (SAS) or all three sides (SSS). Use the law of sines when you have an angle and the side opposite it, or two angles and any side (AAS or ASA).

Q: Can the law of cosines find an angle, not just a side?

A: Yes. Rearranging the same identity gives cos(C) = (a^2 + b^2 - c^2) / (2ab). Enter all three sides and an arccos call returns the included angle C in degrees or radians.

Q: Does the law of cosines work for right and obtuse triangles?

A: Yes. When C is 90 degrees the cosine term vanishes and the law reduces to c^2 = a^2 + b^2, which is the Pythagorean theorem. For obtuse triangles, cos(C) is negative, which grows c^2 by 2ab*|cos(C)| and makes the third side longer than the right-triangle case.

Q: What is the law of cosines formula?

A: c^2 = a^2 + b^2 - 2ab*cos(C). The same identity rearranges to cos(C) = (a^2 + b^2 - c^2) / (2ab) when you have all three sides and want the included angle. The two forms are algebraically equivalent.

Q: How accurate is the law of cosines calculator?

A: The calculator evaluates the standard c^2 = a^2 + b^2 - 2ab*cos(C) identity in JavaScript, which is accurate to about fifteen significant digits. The panel rounds each output to two decimal places, and the angles A and B may show a small drift in the last digit because of that rounding.