Skip to content
CalculatorAtlas

Law of Cosines Calculator

Tested

Third side of a triangle from two sides and the included angle (law of cosines).

Tested, not yet published. The formula for this calculator is implemented and passes its automated checks. This page stays non-indexable until it is reviewed and published.

°

Results

Enter your values and press Calculate. Results appear here.

  • • Result

Quick answer

The law of cosines gives a side from two sides and the included angle: a² = b² + c² − 2bc·cos A. With b = 3, c = 4 and A = 90°, a = 5, the Pythagorean case.

Enter two sides and the angle between them. The calculator returns the third side.

Related tools: Sine Rule Calculator: Apply the sine rule to find a missing side or angle of a triangle from an angle and its opposite side. Trigonometry Calculator: All six trigonometric functions of an angle. Triangle Calculator: Area, perimeter, angles and type of a triangle from its three sides.

How to use the Law of Cosines Calculator

  1. Enter side b (above 0).
  2. Enter side c (above 0).
  3. Enter included angle A (°) (between 0 and 179.999999).
  4. Press Calculate to see the result, and use Reset to start again.
Inputs of the Law of Cosines Calculator
InputWhat to enterAllowed values
Side bA number> 0
Side cA number> 0
Included angle AA number, in °> 0, ≤ 179.999999

Formula and method

Formula

a² = b² + c² − 2bc·cos A

IEEE-754 double precision; shown to at most 6 decimal places.

Law of cosines.

Worked examples

These examples are verified: each one is an automated test case that the live calculator must reproduce exactly.

Example 1

Inputs: Side b = 3; Side c = 4; Included angle A = 90.

Results of example 1
ResultValue
Side a5

Example 2

Inputs: Side b = 1; Side c = 1; Included angle A = 60.

Results of example 2
ResultValue
Side a1

The first line is the headline result (side a). IEEE-754 double precision; shown to at most 6 decimal places.

Generalising Pythagoras

When A = 90°, cos A = 0 and the formula reduces to a² = b² + c². For A = 60° with b = 3 and c = 4: a² = 9 + 16 − 12 = 13, so a = 3.606.

Where this estimate stops applying

The included angle must be between 0° and 180°. Use the formula to find angles too: cos A = (b² + c² − a²) ÷ 2bc. For two sides and a non-included angle use the law of sines, which can have two solutions.

How the result changes with side b

Holding every other input at the first worked example, this table changes only side b. It shows how sensitive the answer is to that one value; each row was produced by running this calculator.

How the result changes with side b
Side bSide a
1.54.272002
35
67.211103
1212.649111

What happens with invalid input

These messages are produced by the calculator itself, so you know what to fix.

  • Included angle A: entering "0" shows "Included angle A must be greater than 0." beside that field and no result.

Choosing between the Law of Cosines Calculator and similar calculators

Each row shows what a related calculator on this site asks for and what it returns, so you can pick the one that matches your question.

Choosing between the Law of Cosines Calculator and similar calculators
CalculatorYou enterIt returns
[Sine Rule Calculator](/math/sine-rule-calculator/)angle A, side a and angle BSide b
[Trigonometry Calculator](/math/trigonometry-calculator/)angle and unitsin
[Triangle Calculator](/math/triangle-calculator/)side a, side b and side cArea
[Right Triangle Calculator](/math/right-triangle-calculator/)leg a and leg bHypotenuse c
[Cosine Rule Calculator](/math/cosine-rule-calculator/)side b, side c and included angle ASide a

Background: trigonometry

In a right triangle, sin θ is the opposite side over the hypotenuse, cos θ the adjacent side over the hypotenuse and tan θ the opposite over the adjacent. Their reciprocals are cosecant, secant and cotangent. At 30° the values are sin = 0.5, cos = 0.866025 and tan = 0.577350.

Check the angle unit before you calculate: degrees convert to radians by multiplying by π/180, so 30° is about 0.5236 rad. Some values are undefined, for example tan 90°, because the cosine is zero there and the ratio would divide by zero.

Assumptions and limitations

  • Angle between 0° and 180°

If a required value is empty, not a number, or outside its allowed range, the form marks that field with a message and shows no result instead of a misleading number. The automated checks deliberately try invalid entries for included angle A to confirm this.

Frequently asked questions

When do I use it?

Use it when you know two sides and the included angle (SAS) or all three sides (SSS).

What if A is obtuse?

cos A is negative, so the side is longer.

How is it related to Pythagoras?

It's the general form.

What does the Law of Cosines Calculator calculate?

Third side of a triangle from two sides and the included angle (law of cosines). It returns Side a.

What formula does the Law of Cosines Calculator use?

a² = b² + c² − 2bc·cos A. Law of cosines.

What do I need to enter in the law of Cosines Calculator?

You enter Side b, Side c and Included angle A (°).

How is the result rounded or limited?

IEEE-754 double precision; shown to at most 6 decimal places. Angle between 0° and 180°.

What is an example of a law of Cosines result?

With side b 3, side c 4 and included angle A 90, the side a is 5.

Where does the method come from?

The method follows: OpenStax, Algebra and Trigonometry 2e (Rice University): exponents, radicals, logarithms and inverse trigonometric functions; OpenStax, Precalculus 2e (Rice University): vectors, polar coordinates and trigonometry.

Sources

  • OpenStax, Algebra and Trigonometry 2e (Rice University): exponents, radicals, logarithms and inverse trigonometric functions
  • OpenStax, Precalculus 2e (Rice University): vectors, polar coordinates and trigonometry

Content last reviewed 2026-11-04. Formulas and worked examples are checked by automated tests against independently computed values.