Law of Cosines Calculator
The law of cosines calculator can help you solve a vast number of triangular problems. You will learn what is the law of cosines (also known as the cosine rule), the law of cosines formula, and its applications. Scroll down to find out when and how to use the law of cosines, and check out the proofs of this law. Thanks to this triangle calculator, you will be able to find the properties of any arbitrary triangle quickly.
But if, somehow, you're wondering what the heck is cosine, better have a look at our cosine calculator.
Law of cosines formula
The law of cosines states that, for a triangle with sides and angles denoted with symbols as illustrated above,
a² = b² + c²  2bc * cos(α)
b² = a² + c²  2ac * cos(β)
c² = a² + b²  2ab * cos(γ)
For a right triangle, the angle gamma, which is the angle between legs a
and b
, is equal to 90°. The cosine of 90° = 0, so in that special case, the law of cosines formula is reduced to the wellknown equation of Pythagorean theorem:
a² = b² + c²  2bc * cos(90°)
a² = b² + c²
What is the law of cosines?
The law of cosines (alternatively the cosine formula or cosine rule) describes the relationship between the lengths of a triangle's sides and the cosine of its angles. It can be applied to all triangles, not only the right triangles. This law generalizes the Pythagorean theorem, as it allows you to calculate the length of one of the sides, given you know the length of both the other sides and the angle between them.
The law appeared in Euclid's Element, a mathematical treatise containing definitions, postulates, and geometry theorems. Euclid didn't formulate it in the way we learn it today, as the concept of cosine had not been developed yet.
AB² = CA² + CB²  2 * CA * CH
(for acute angles, '+' for obtuse)
However, we may reformulate Euclid's theorem easily to the current cosine formula form:
CH = CB * cos(γ)
, so AB² = CA² + CB²  2 * CA * (CB * cos(γ))
Changing notation, we obtain the familiar expression:
c² = a² + b²  2ab * cos(γ)
The first explicit equation of the cosine rule was presented by Persian mathematician d'AlKashi in the 15th century. In the 16th century, the law was popularized by famous French mathematician Viète before it received its final shape in the 19th century.
Applications of the law of cosines
You can transform these law of cosines formulas to solve some problems of triangulation (solving a triangle). You can use them to find:
 The third side of a triangle, knowing two sides and the angle between them (SAS):
a = √[b² + c²  2bc * cos(α)]
b = √[a² + c²  2ac * cos(β)]
c = √[a² + b²  2ab * cos(γ)]
 The angles of a triangle, knowing all three sides (SSS):
α = arccos [(b² + c²  a²)/(2bc)]
β = arccos [(a² + c²  b²)/(2ac)]
γ = arccos [(a² + b²  c²)/(2ab)]
 The third side of a triangle, knowing two sides and an angle opposite to one of them (SSA):
a = b * cos(γ) ± √[c²  b² * sin²(γ)]
b = c * cos(α) ± √[a²  c² * sin²(α)]
c = a * cos(β) ± √[b²  a² * sin²(β)]
Just remember that knowing two sides and an adjacent angle can yield two distinct possible triangles (or one or zero positive solutions, depending on the given data). That's why we've decided to implement SAS and SSS in this tool, but not SSA.
The law of cosines is one of the basic laws and it's widely used for many geometric problems. We also take advantage of that law in many Omnitools, to mention only a few:
 triangle angle calculator
 triangle area calculator
 perimeter of a triangle calculator
 triangular prism calculator
Also, you can combine the law of cosines calculator with the law of sines to solve other problems, for example, finding the side of the triangle, given two of the angles and one side (AAS and ASA).
Law of cosines proofs
There are many ways in which you can prove the law of cosines equation. You've already read about one of them  it comes directly from Euclid's formulation of the law and an application of the Pythagorean theorem. You can write the other proofs of the law of cosines using:
1. Trigonometry
Draw a line for the height of the triangle and divide the side perpendicular to it into two parts:
b = b₁ + b₂
From sine and cosine definitions, b₁
might be expressed as a * cos(γ)
and b₂ = c * cos(α)
. Hence:
b = a * cos(γ) + c * cos(α)
and by multiplying it by b
, we get:
b² = ab * cos(γ) + bc * cos(α)
(1)
Analogical equations may be derived for other two sides:
a² = ac * cos(β) + ab * cos(γ)
(2)
c² = bc * cos(α) + ac * cos(β)
(3)
To finish the law of cosines proof, you need to add the equation (1) and (2) and subtract (3):
a² + b²  c² = ac * cos(β) + ab * cos(γ) + bc * cos(α) + ab * cos(γ)  bc * cos(α)  ac * cos(β)
Reduction and simplification of the equation give one of the forms of the cosine rule:
a² + b²  c² = 2ab * cos(γ)
c² = a² + b²  2ab * cos(γ)
By changing the order in which they are added and subtracted, you can derive the other law of cosine formulas.
2. Distance formula
Let C = (0,0)
, A = (b,0)
, as in the image.
To find the coordinates of B, we can use the definition of sine and cosine:
B = (a * cos(γ), a * sin(γ))
From the distance formula, we can find that:
c = √[(x₂  x₁)² + (y₂  y₁)²] = √[(a * cos(γ)  b)² + (a * sin(γ)  0)²]
Thus:
c² = a² * cos(γ)²  2ab * cos(γ) + b² + a² * sin(γ)²
c² = b² + a²(sin(γ)² + cos(γ)²)  2ab * cos(γ)
As a sum of squares of sine and cosine is equal to 1, we obtain the final formula:
c² = a² + b²  2ab * cos(γ)
3. Ptolemy's theorem
Another law of cosines proof that is relatively easy to understand uses Ptolemy's theorem:

Assume we have the triangle ABC drawn in its circumcircle, as in the picture.

Construct the congruent triangle ADC, where AD = BC and DC = BA

The heights from points B and D split the base AC by E and F, respectively. CE equals FA.

From the cosine definition, we can express CE as
a * cos(γ)
. 
Thus, we can write that
BD = EF = AC  2 * CE = b  2 * a * cos(γ)
. 
Then, for our quadrilateral ADBC, we can use Ptolemy's theorem, which explains the relation between the four sides and two diagonals. The theorem states that for cyclic quadrilaterals, the sum of products of opposite sides is equal to the product of the two diagonals:
BC * DA + CA * BD = AB * CD
so in our case:
a² + b * (b  2 * a * cos(γ)) + a² = c²

After reduction we get the final formula:
c² = a² + b²  2ab * cos(γ))
The great advantage of these three proofs is their universality  they work for acute, right, and obtuse triangles.
 Using the law of sines
 Using the definition of dot product
 Comparison of areas
 Geometry of the circle
The last two proofs require the distinction between different triangle cases. The one based on the definition of dot product is shown in another article, and the proof using the law of sines is quite complicated, so we have decided not to reproduce it here. If you're curious about these law of cosines proofs, check out the
explanation.How to use the law of cosines calculator

Start with formulating your problem. For example, you may know two sides of the triangle and the angle between them and are looking for the remaining side.

Input the known values into the appropriate boxes of this triangle calculator. Remember to doublecheck with the figure above whether you denoted the sides and angles with correct symbols.

Watch our law of cosines calculator perform all the calculations for you!
Law of cosines  SSS example
If your task is to find the angles of a triangle given all three sides, all you need to do is to use the transformed cosine rule formulas:
α = arccos [(b² + c²  a²)/(2bc)]
β = arccos [(a² + c²  b²)/(2ac)]
γ = arccos [(a² + b²  c²)/(2ab)]
Let's calculate one of the angles. Assume we have a = 4 in, b = 5 in and c = 6 in. We'll use the first equation to find α:
α = arccos [(b² + c²  a²)/(2bc)]
= arccos [(5² + 6²  4²)/(2 * 5 * 6)]
= arccos [(25 + 36  16)/60]
= arccos [(45/60)] = arccos [0.75]
α = 41.41°
You may calculate the second angle from the second equation in an analogical way, and the third angle you can find knowing that the sum of the angles in a triangle is equal to 180° (π/2).
If you want to save some time, type the side lengths into our law of sines calculator  our tool is a safe bet! Just follow these simple steps:
 Choose the option depending on given values. We need to pick the second option  SSS (3 sides).
 Enter the known values. Type the sides: a = 4 in, b = 5 in and c = 6 in.
 The calculator displays the result! In our case the angles are equal to α = 41.41°, β = 55.77° and γ = 82.82°.
After such an explanation, we're sure that you understand what the law of cosine is and when to use it. Give this tool a try, solve some exercises, and remember that practice makes permanent!
FAQ
When should I use the law of cosines?
Use the law of cosines if you need to calculate:
 A side of a triangle given two other sides and the angle between them.
 The three angles of a triangle given its sides.
 A side of a triangle given two other sides and an angle opposite to one of these sides.
When should I use the law of cosines vs the Pythagorean theorem?
The law of cosines is a generalization of the Pythagorean theorem, so whenever the latter works, the former can be applied as well. Not the other way round, though!
Is the law of cosines valid only for right triangles?
No, the law of cosines is valid for all triangles. In fact, when you apply the law of cosines to a right triangle, you'll arrive at the good old Pythagorean theorem.
What is the third side of a triangle with sides 5 and 6?
Besides the two sides, you need to know one of the inner angles of the triangle. Let's say it's the angle γ = 30° between the sides 5 and 6. Then:
 Recall the law of cosines formula c² = a² + b²  2ab × cos(γ)
 Plug in the values a = 5, b = 6, γ = 30°.
 We obtain c² = 25 + 36  2 × 5 × 6 × cos(30) ≈ 9.
 Therefore, c ≈ 3. Remember to include the units if you were given any!