Law of Cosines Calculator - Solve SSS and SAS Triangles

Solve a triangle from three sides or two sides and the included angle using the law of cosines. Worked examples and the formula for every side.

01 solve

Result

    Figure

    Show the working

      The Triangle Law of Cosines Calculator solves a triangle when three sides are known (SSS), or when two sides and the angle between them are known (SAS). Enter the known measurements, and the tool applies the law of cosines to find the remaining sides and angles, showing each substitution along the way.

      The law of cosines generalizes the Pythagorean theorem to any triangle, not just right triangles, which is why it is the tool of choice whenever a triangle problem does not include a convenient 90-degree angle to work with.

      Apply the law of cosines

      Concept diagram: Inputs leads to law of cosines leads to ResultInputslaw of cosinesResult
      Apply the law of cosines.

      The law of cosines relates one side of a triangle to the other two sides and the angle between them.

      c² = a² + b² − 2ab·cos(C)

      Here, C is the angle opposite side c. Rearranged versions of the same relation solve for any side using the angle opposite it and the other two sides.

      Solve a triangle from three sides (SSS)

      Concept diagram: Inputs leads to a triangle from three sides (SSS) leads to ResultInputsa triangle from threesides (SSS)Result
      Solve a triangle from three sides (SSS).

      When all three sides are known, the law of cosines rearranges to solve for each angle in turn.

      cos(A) = (b² + c² − a²) / (2bc)

      Worked example: a triangle with sides a = 5, b = 7, c = 8. Find angle A.

      1. Substitute into the rearranged formula. cos(A) = (7² + 8² − 5²) / (2 × 7 × 8).

      2. Simplify the numerator. 49 + 64 − 25 = 88.

      3. Simplify the denominator. 2 × 7 × 8 = 112.

      4. Divide and take the inverse cosine. cos(A) = 88/112 ≈ 0.7857, so A = cos⁻¹(0.7857) ≈ 38.2°.

      The remaining two angles follow the same method, or the faster route once one angle is known: use the law of sines for the second angle, then subtract both from 180° for the third.

      Solve a triangle from two sides and the included angle (SAS)

      Concept diagram: Inputs leads to a triangle from two sides and… leads to ResultInputsa triangle from twosides and…Result
      Solve a triangle from two sides and the included angle (SAS).

      When two sides and the angle between them are known, the law of cosines finds the third side directly. Worked example: a triangle with a = 6, b = 9, and included angle C = 45°. 1. Substitute into the formula. c² = 6² + 9² − 2(6)(9)cos(45°).

      2. Calculate each term. 36 + 81 − 108 × 0.7071 ≈ 117 − 76.37 ≈ 40.63.

      3. Take the square root. c ≈ √40.63 ≈ 6.37.

      With the third side found, the remaining two angles can then be found using the law of sines, since a full side-angle pair (side c opposite angle C) is now available.

      Recognize when the law of cosines is required

      Concept diagram: Inputs leads to when law of cosines is required leads to ResultInputswhen law of cosines isrequiredResult
      Recognize when the law of cosines is required.

      The law of cosines is needed specifically for SSS (three sides, no angles) and SAS (two sides and their included angle) cases, because the law of sines cannot start without at least one known angle paired with its opposite side.

      Once the law of cosines produces that first angle-side pair, the law of sines can finish the remaining calculations more directly.

      CaseYou knowMethod
      SSSthree sideslaw of cosines
      SAStwo sides and the included anglelaw of cosines, then law of sines

      Check the result with the Pythagorean special case

      Concept diagram: Inputs leads to result with Pythagorean special case leads to ResultInputsresult with Pythagoreanspecial caseResult
      Check the result with the Pythagorean special case.

      When the included angle in an SAS problem is exactly 90°, cos(90°) = 0, and the law of cosines reduces exactly to the Pythagorean theorem: c² = a² + b². This is a useful sanity check, confirming that the law of cosines is a genuine generalization rather than an unrelated formula that happens to solve similar problems.

      Solve for a second angle to complete the SSS example

      Concept diagram: Inputs leads to for a second angle to complete SSS… leads to ResultInputsfor a second angle tocomplete SSS…Result
      Solve for a second angle to complete the SSS example.

      Continuing the a = 5, b = 7, c = 8 triangle from above, angle B follows the same rearranged formula with the sides relabeled. 1. Substitute into the rearranged formula. cos(B) = (5² + 8² − 7²) / (2 × 5 × 8) = (25 + 64 − 49) / 80 = 40/80 = 0.5.

      2. Take the inverse cosine. B = cos⁻¹(0.5) = 60°.

      3. Find the third angle. 180 − 38.2 − 60 = 81.8° for angle C, using the angle sum found from the earlier A value on this page.

      Frequently asked questions

      What is the law of cosines formula?

      c² = a² + b² − 2ab·cos(C), where C is the angle opposite side c. It generalizes the Pythagorean theorem to triangles without a right angle.

      When do you use the law of cosines instead of the law of sines?

      Use the law of cosines for SSS (three known sides) or SAS (two sides and the included angle) cases, since the law of sines needs at least one angle paired with its opposite side to begin.

      How do you find an angle using the law of cosines?

      Rearrange the formula to solve for cosine: cos(A) = (b² + c² − a²) / (2bc), then take the inverse cosine of the result to find angle A.

      Does the law of cosines work for right triangles too?

      Yes. When the included angle is 90°, cos(90°) = 0 and the formula reduces exactly to the Pythagorean theorem, confirming it as a generalization rather than a separate rule.

      Can the law of cosines have an ambiguous result like SSA?

      No. Unlike the law of sines in the SSA case, the law of cosines applied to SSS or SAS gives a single, unambiguous answer, since it does not rely on an inverse sine function that can return two valid angles.

      What if the three given sides don't form a valid triangle?

      If the sum of the two shorter sides is less than or equal to the longest side, no valid triangle exists, and the calculator will flag this rather than returning an incorrect angle.

      Can I use the law of cosines to find all three angles?

      Yes. Apply the rearranged formula once for each angle, or find one angle this way and use the law of sines and the 180-degree angle sum for the remaining two, which is typically faster.

      Summary

      The law of cosines, c² = a² + b² − 2ab·cos(C), solves SSS triangles by finding each angle from the rearranged cosine formula, and SAS triangles by finding the third side directly, such as a triangle with sides 6 and 9 and a 45° included angle giving a third side of about 6.37.

      It generalizes the Pythagorean theorem, reducing to it exactly when the included angle is 90°, and gives an unambiguous single answer unlike the SSA case under the law of sines.