Law of cosines calculator

Solve a triangle's missing side or angle with the cosine rule. Explore SAS and SSS problems with live geometry, formulas, and step-by-step explanations.

Report error
Missing side c
6.245
from a = 5, b = 7, C = 60°
Area
15.16
K = ½ab sin C
Perimeter
18.245
P = a + b + c

Live triangle geometry

The triangle redraws as the side lengths or included angle change. Labels always match the current solution.
LIVE
Included angle 60°Third side c = 6.245
current triangleDashed line = altitude

Third side vs. included angle

For fixed a and b, the law of cosines traces the possible third side as C moves from a nearly flat triangle toward 180°.
LIVE
Current angle 60°Current c 6.245
c(C) = √(a²+b²−2ab cos C)Current point

Cosine-rule balance

See how the cosine term changes the sum of the two squared sides to produce c². The sign flips at 90°.
LIVE
a² + b² 742ab cos C 35c² 39
positive/negative cosine correction
Live intelligence

What the current geometry tells you

LIVE
Side a5
Side b7
Angle C60°
Side c6.245
Because C is acute, cos(C) is positive, so the correction term is subtracted from a² + b². The result is shorter than the right-triangle value √(a²+b²).

Triangle at a glance

Current calculated values
QuantityValueMeaning
c² = a² + b² − 2ab cos C
Core idea

What is the law of cosines?

The law of cosines, also called the cosine rule, relates the three side lengths of a triangle to the cosine of its angles. It works for acute, right, and obtuse triangles, so it extends the Pythagorean theorem beyond right triangles.

c² = a² + b² − 2ab cos C

Here, a and b are the two sides enclosing angle C, while c is the side opposite C. The same relationship can be written cyclically for the other two sides.

c b a C AB

The formula appears in all three equivalent forms: a² = b² + c² − 2bc cos A, b² = a² + c² − 2ac cos B, and c² = a² + b² − 2ab cos C.

Formula system

Law of cosines formulas

Solving for a side

a = √(b² + c² − 2bc cos A)
b = √(a² + c² − 2ac cos B)
c = √(a² + b² − 2ab cos C)

Solving for an angle

A = arccos((b²+c²−a²)/(2bc))
B = arccos((a²+c²−b²)/(2ac))
C = arccos((a²+b²−c²)/(2ab))

The side forms correspond to the SAS situation, while the inverse-cosine forms solve angles from SSS data. CalculatorSoup lists all three side and angle forms and the associated triangle quantities.

Why the formula works

Geometric interpretation: the cosine correction

Imagine dropping an altitude from the vertex at angle C. The projection of one side onto the other introduces a term involving cos C. That projection is what separates the cosine rule from the simple right-triangle relationship.

a b projection C h

Another way to see the same relationship is through coordinates: place one vertex at the origin, place a second on the x-axis, and express the third point using sine and cosine. Expanding the distance formula produces the same cosine-rule expression. Omni Calculator presents both the trigonometric-height and distance-formula routes, along with other proof approaches.

Worked examples

Step-by-step examples

Example 1 — SAS: find the third side

Suppose a = 5, b = 7, and the included angle is C = 60°.

c² = 5² + 7² − 2(5)(7)cos60°
c² = 25 + 49 − 70(0.5) = 39
c = √39 ≈ 6.245

The calculator also reports the area using K = ½ab sin C and the perimeter using P = a + b + c. CalculatorSoup gives the same standard triangle perimeter and area relationships alongside the cosine rule.

Example 2 — SSS: find an angle

Let a = 4, b = 5, and c = 6. To find angle A:

A = arccos((b² + c² − a²)/(2bc))
A = arccos((25 + 36 − 16)/60)
A = arccos(0.75) ≈ 41.41°

This matches the SSS workflow described by Omni Calculator. Once two angles are known, the third can also be obtained from the 180° angle sum.

Triangle behavior

Acute, right, and obtuse triangles

C < 90° — acute

cos C is positive, so 2ab cos C is positive and is subtracted from a²+b². Therefore c² is smaller than a²+b².

C = 90° — right

cos 90° = 0, so the correction disappears and c² = a²+b². The law of cosines becomes the Pythagorean theorem.

C > 90° — obtuse

cos C is negative, so subtracting 2ab cos C adds a positive amount. The opposite side becomes longer than √(a²+b²).

C → 180°

The triangle approaches a straight line and c approaches a+b. The area approaches zero.

Validity & checks

How to check whether a triangle is valid

For three side lengths, the triangle inequality must hold:

a + b > c    b + c > a    c + a > b

For SAS, the computed side is generated directly from the cosine rule. For SSS, the inverse-cosine argument should remain between −1 and 1 apart from tiny floating-point rounding. The calculator clamps only microscopic numerical drift and otherwise reports invalid input rather than manufacturing a triangle.

CheckMeaningExpected result
a+b>cTwo sides must exceed the thirdTrue
|a−b|<cThird side must exceed the side differenceTrue
−1≤cos C≤1Inverse cosine must be definedTrue
A+B+C=180°Angle consistency180°
Questions

Law of cosines FAQ

When should I use the law of cosines?
Use it to find a side when you know two sides and their included angle (SAS), or to find an angle when all three sides are known (SSS). It is also a generalization of the Pythagorean theorem.
Does the law of cosines work only for right triangles?
No. It works for all triangles. A right triangle is simply the special case where the relevant angle is 90° and the cosine term becomes zero.
What is the difference between SAS and SSS?
SAS means two sides and the included angle are known; it determines the opposite side. SSS means all three sides are known; inverse cosine determines the angles.
Why can an obtuse triangle have c² greater than a²+b²?
Because cos C is negative for an obtuse angle. The term −2ab cos C therefore becomes positive, increasing c².
Can I use the law of cosines with units such as cm or inches?
Yes. Keep all side lengths in the same unit. The resulting side, perimeter, and area then follow the corresponding unit system.