Skip to main content

Law of Cosines Calculator

Solve law cosines problems step-by-step with our free calculator. See formulas, worked examples, and clear explanations.

Skip to calculator
Mathematics

Law of Cosines Calculator

Solve triangles using the law of cosines. Find unknown sides from SAS data or unknown angles from SSS data. Get area, perimeter, inradius, circumradius, and triangle classification.

Last updated: December 2025Reviewed by NovaCalculator Mathematics Team

Calculator

Adjust values & calculate
Side c (opposite angle C)
6.244998
Acute Triangle
Angle A
43.8979 deg
Angle B
76.1021 deg
Angle C
60.0000 deg
Area
15.1554
Perimeter
18.2450
Inradius
1.6613
Circumradius
3.6056
Angle Sum Verification
180.0000 deg
Your Result
Side c = 6.244998 | A = 43.8979 deg | B = 76.1021 deg | Acute
Share Your Result
Understand the Math

Formula

c2 = a2 + b2 - 2ab cos(C)

The law of cosines relates the three sides of a triangle to the cosine of one angle. Rearranged to find an angle: cos(C) = (a2 + b2 - c2) / (2ab). It generalizes the Pythagorean theorem to all triangles.

Last reviewed: December 2025

Worked Examples

Example 1: Finding a Side (SAS)

Triangle has sides a = 5, b = 7, and included angle C = 60 degrees. Find side c.
Solution:
c2 = a2 + b2 - 2ab cos(C) c2 = 25 + 49 - 2(5)(7)cos(60) c2 = 74 - 70(0.5) = 74 - 35 = 39 c = sqrt(39) = 6.244998 Finding angle A: cos(A) = (b2+c2-a2)/(2bc) = (49+39-25)/(2(7)(6.245)) = 63/87.43 = 0.72058 A = arccos(0.72058) = 43.897 degrees B = 180 - 43.897 - 60 = 76.103 degrees
Result: c = 6.2450 | A = 43.897 deg | B = 76.103 deg | Area = 15.1554

Example 2: Finding Angles (SSS)

Triangle has sides a = 8, b = 6, c = 10. Find all angles.
Solution:
cos(C) = (a2+b2-c2)/(2ab) = (64+36-100)/(2(8)(6)) = 0/96 = 0 C = arccos(0) = 90 degrees (right triangle!) cos(A) = (b2+c2-a2)/(2bc) = (36+100-64)/(2(6)(10)) = 72/120 = 0.6 A = arccos(0.6) = 53.130 degrees B = 180 - 90 - 53.130 = 36.870 degrees
Result: A = 53.130 deg | B = 36.870 deg | C = 90 deg | Right triangle
Expert Insights

Background & Theory

The Law of Cosines Calculator applies the following established principles and formulas. Mathematics rests on a hierarchy of number systems, each extending the previous. The natural numbers (1, 2, 3, ...) support counting and ordering. The integers add negative values and zero, enabling subtraction without restriction. The rational numbers, expressible as p/q where p and q are integers and q is nonzero, close the system under division. The real numbers fill the gaps left by irrationals such as the square root of 2 or pi, forming a complete ordered field. The complex numbers, written as a + bi where i is the square root of negative one, complete the algebraic closure of the reals and allow every polynomial to have a root. Prime factorization states that every integer greater than one is uniquely expressible as a product of primes, a result known as the Fundamental Theorem of Arithmetic. Computing the greatest common divisor (GCD) of two integers relies most efficiently on the Euclidean algorithm: repeatedly replace the larger number with the remainder when it is divided by the smaller, until the remainder is zero. The last nonzero remainder is the GCD. The least common multiple (LCM) follows from the identity LCM(a, b) = |a * b| / GCD(a, b). Modular arithmetic defines equivalence classes of integers that share the same remainder under division by a modulus n. Fermat's Little Theorem and Euler's Theorem arise from this structure and underpin modern cryptography. Logarithms are the inverses of exponential functions. If b raised to the power x equals y, then the logarithm base b of y equals x. The natural logarithm uses base e, approximately 2.71828. Combinatorics counts arrangements and selections. The number of ordered arrangements (permutations) of r objects from n distinct objects is nPr = n! / (n - r)!. The number of unordered selections (combinations) is nCr = n! / (r! * (n - r)!). Pascal's triangle arranges these binomial coefficients so that each entry equals the sum of the two entries directly above it. The Fibonacci sequence, defined by F(1) = 1, F(2) = 1, and F(n) = F(n-1) + F(n-2), appears throughout nature and connects deeply to the golden ratio via Binet's formula.

History

The history behind the Law of Cosines Calculator traces back through the following developments. Mathematics as a systematic discipline traces to ancient Mesopotamia. Babylonian clay tablets dating to around 1800 BCE demonstrate knowledge of quadratic equations, Pythagorean triples, and base-60 arithmetic, suggesting a practical mathematical tradition far preceding Greek formalism. Euclid of Alexandria compiled the Elements around 300 BCE, establishing the axiomatic method that would define rigorous mathematics for over two thousand years. His work organized plane geometry, number theory, and proportion into logically chained propositions derived from a small set of postulates. The algorithm bearing his name for computing GCDs appears in Book VII and remains in use today. In the 9th century, the Persian scholar Muhammad ibn Musa Al-Khwarizmi wrote Al-Kitab al-mukhtasar fi hisab al-jabr wal-muqabala, the treatise whose title gave algebra its name. He systematized the solution of linear and quadratic equations and described procedures that operated on unknowns as objects, a conceptual leap away from purely numerical calculation. Rene Descartes introduced coordinate geometry in 1637 by uniting algebra and Euclidean geometry, allowing curves to be studied through equations. This synthesis set the stage for calculus. Isaac Newton and Gottfried Wilhelm Leibniz independently developed calculus during the 1660s and 1670s, triggering a priority dispute that lasted decades and divided British and Continental mathematicians. Carl Friedrich Gauss proved the Fundamental Theorem of Algebra in 1799, showing that every nonconstant polynomial has at least one complex root. His Disquisitiones Arithmeticae of 1801 established modern number theory. David Hilbert's formalist program at the turn of the 20th century sought to place all of mathematics on an explicit axiomatic foundation, a project that Kurt Godel's incompleteness theorems of 1931 showed to be fundamentally limited. Alan Turing's work in the 1930s on computability introduced the theoretical model of the stored-program computer and linked mathematical logic directly to the limits of algorithmic calculation. His proof that no algorithm can decide in general whether an arbitrary program will halt or run forever placed fundamental boundaries on what mathematics can mechanically determine, and it opened the discipline now known as theoretical computer science.

Share this calculator

Explore More

Frequently Asked Questions

The law of cosines is a fundamental theorem in trigonometry that relates the lengths of the sides of any triangle to the cosine of one of its angles. The formula states c2 = a2 + b2 - 2ab cos(C), where a, b, and c are the three sides and C is the angle opposite side c. It can be rearranged to find any side or any angle. When C = 90 degrees, cos(C) = 0, and the formula simplifies to the Pythagorean theorem c2 = a2 + b2. Thus, the law of cosines is a generalization of the Pythagorean theorem that works for all triangles, not just right triangles. It is one of the most important tools in trigonometry alongside the law of sines.
Use the law of cosines in two specific situations: when you know two sides and the included angle (SAS) and need to find the third side, or when you know all three sides (SSS) and need to find an angle. The law of sines is better when you know a side and its opposite angle plus one other piece of information (ASA or AAS). A key advantage of the law of cosines for the SSS case is that it avoids the ambiguous case problem that can occur with the law of sines (where an angle could be acute or obtuse). The law of cosines always gives a unique, unambiguous result for an angle when all three sides are known. In practice, many problems can be solved with either law, but choosing the right one simplifies the calculation.
To solve a triangle completely means finding all three sides and all three angles. For SAS (two sides and included angle known): use c2 = a2 + b2 - 2ab cos(C) to find the third side, then use the law of cosines again or the law of sines to find the remaining angles. For SSS (all sides known): rearrange to cos(C) = (a2 + b2 - c2)/(2ab) to find each angle. Always verify that your three angles sum to 180 degrees as a check. When finding angles from the SSS case, it is best practice to find the largest angle first (opposite the longest side) using the law of cosines, because the law of cosines unambiguously determines whether the angle is acute or obtuse. Then find the remaining angles using either law.
The law of cosines can be derived using coordinate geometry. Place triangle ABC with vertex C at the origin and side b along the positive x-axis. Then A is at coordinates (b, 0) and B is at (a cos(C), a sin(C)). The distance from A to B (which is side c) is found using the distance formula: c2 = (a cos(C) - b)2 + (a sin(C))2. Expanding: c2 = a2 cos2(C) - 2ab cos(C) + b2 + a2 sin2(C). Since cos2(C) + sin2(C) = 1, this simplifies to c2 = a2 + b2 - 2ab cos(C). An alternative derivation uses the vector dot product: if vectors represent two sides, their difference gives the third side, and expanding the dot product of that difference yields the law of cosines.
The law of cosines has extensive real-world applications. In surveying and land measurement, it calculates distances between points when direct measurement is impossible. In navigation, it determines the distance between two locations given bearings and a known baseline. In physics, it resolves force vectors when two forces act at an angle and you need the resultant magnitude. In astronomy, it helps calculate distances between celestial objects. In construction, it verifies that structures are square and calculates diagonal measurements. In GPS technology, trilateration algorithms use the law of cosines to determine position from satellite distances. Even in sports analytics, it calculates angles and distances for trajectory analysis in golf, baseball, and other projectile sports.
The expression a2 + b2 - 2ab cos(C) can approach zero but never becomes negative for a valid triangle, because the result represents c2 (a squared length). However, the cosine term itself can be negative: when angle C is obtuse (greater than 90 degrees), cos(C) is negative, making -2ab cos(C) positive. This means c2 = a2 + b2 + |2ab cos(C)|, resulting in c being longer than the Pythagorean distance. When angle C equals exactly 90 degrees, the cosine term vanishes and the formula becomes the Pythagorean theorem. When rearranging to find an angle, cos(C) = (a2+b2-c2)/(2ab), a negative result for cos(C) means the angle is obtuse, which is perfectly valid and indicates the triangle has one angle greater than 90 degrees.
Educational Note: This calculator is provided for educational and informational purposes. Results are based on the formulas and inputs provided. Always verify important calculations independently. NovaCalculator processes calculator inputs client-side; optional analytics follow visitor consent settings.Reviewed by: NovaCalculator Mathematics Team โ€” Verified against standard mathematical and scientific references. Last reviewed: December 2025. ยฉ 2024โ€“2026 NovaCalculator.

Share this calculator

Formula

c2 = a2 + b2 - 2ab cos(C)

The law of cosines relates the three sides of a triangle to the cosine of one angle. Rearranged to find an angle: cos(C) = (a2 + b2 - c2) / (2ab). It generalizes the Pythagorean theorem to all triangles.

Worked Examples

Example 1: Finding a Side (SAS)

Problem: Triangle has sides a = 5, b = 7, and included angle C = 60 degrees. Find side c.

Solution: c2 = a2 + b2 - 2ab cos(C)\nc2 = 25 + 49 - 2(5)(7)cos(60)\nc2 = 74 - 70(0.5) = 74 - 35 = 39\nc = sqrt(39) = 6.244998\n\nFinding angle A: cos(A) = (b2+c2-a2)/(2bc) = (49+39-25)/(2(7)(6.245)) = 63/87.43 = 0.72058\nA = arccos(0.72058) = 43.897 degrees\nB = 180 - 43.897 - 60 = 76.103 degrees

Result: c = 6.2450 | A = 43.897 deg | B = 76.103 deg | Area = 15.1554

Example 2: Finding Angles (SSS)

Problem: Triangle has sides a = 8, b = 6, c = 10. Find all angles.

Solution: cos(C) = (a2+b2-c2)/(2ab) = (64+36-100)/(2(8)(6)) = 0/96 = 0\nC = arccos(0) = 90 degrees (right triangle!)\n\ncos(A) = (b2+c2-a2)/(2bc) = (36+100-64)/(2(6)(10)) = 72/120 = 0.6\nA = arccos(0.6) = 53.130 degrees\nB = 180 - 90 - 53.130 = 36.870 degrees

Result: A = 53.130 deg | B = 36.870 deg | C = 90 deg | Right triangle

Frequently Asked Questions

What is the law of cosines?

The law of cosines is a fundamental theorem in trigonometry that relates the lengths of the sides of any triangle to the cosine of one of its angles. The formula states c2 = a2 + b2 - 2ab cos(C), where a, b, and c are the three sides and C is the angle opposite side c. It can be rearranged to find any side or any angle. When C = 90 degrees, cos(C) = 0, and the formula simplifies to the Pythagorean theorem c2 = a2 + b2. Thus, the law of cosines is a generalization of the Pythagorean theorem that works for all triangles, not just right triangles. It is one of the most important tools in trigonometry alongside the law of sines.

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

Use the law of cosines in two specific situations: when you know two sides and the included angle (SAS) and need to find the third side, or when you know all three sides (SSS) and need to find an angle. The law of sines is better when you know a side and its opposite angle plus one other piece of information (ASA or AAS). A key advantage of the law of cosines for the SSS case is that it avoids the ambiguous case problem that can occur with the law of sines (where an angle could be acute or obtuse). The law of cosines always gives a unique, unambiguous result for an angle when all three sides are known. In practice, many problems can be solved with either law, but choosing the right one simplifies the calculation.

How do you solve a triangle using the law of cosines?

To solve a triangle completely means finding all three sides and all three angles. For SAS (two sides and included angle known): use c2 = a2 + b2 - 2ab cos(C) to find the third side, then use the law of cosines again or the law of sines to find the remaining angles. For SSS (all sides known): rearrange to cos(C) = (a2 + b2 - c2)/(2ab) to find each angle. Always verify that your three angles sum to 180 degrees as a check. When finding angles from the SSS case, it is best practice to find the largest angle first (opposite the longest side) using the law of cosines, because the law of cosines unambiguously determines whether the angle is acute or obtuse. Then find the remaining angles using either law.

How is the law of cosines derived?

The law of cosines can be derived using coordinate geometry. Place triangle ABC with vertex C at the origin and side b along the positive x-axis. Then A is at coordinates (b, 0) and B is at (a cos(C), a sin(C)). The distance from A to B (which is side c) is found using the distance formula: c2 = (a cos(C) - b)2 + (a sin(C))2. Expanding: c2 = a2 cos2(C) - 2ab cos(C) + b2 + a2 sin2(C). Since cos2(C) + sin2(C) = 1, this simplifies to c2 = a2 + b2 - 2ab cos(C). An alternative derivation uses the vector dot product: if vectors represent two sides, their difference gives the third side, and expanding the dot product of that difference yields the law of cosines.

What real-world problems use the law of cosines?

The law of cosines has extensive real-world applications. In surveying and land measurement, it calculates distances between points when direct measurement is impossible. In navigation, it determines the distance between two locations given bearings and a known baseline. In physics, it resolves force vectors when two forces act at an angle and you need the resultant magnitude. In astronomy, it helps calculate distances between celestial objects. In construction, it verifies that structures are square and calculates diagonal measurements. In GPS technology, trilateration algorithms use the law of cosines to determine position from satellite distances. Even in sports analytics, it calculates angles and distances for trajectory analysis in golf, baseball, and other projectile sports.

Can the law of cosines produce negative values?

The expression a2 + b2 - 2ab cos(C) can approach zero but never becomes negative for a valid triangle, because the result represents c2 (a squared length). However, the cosine term itself can be negative: when angle C is obtuse (greater than 90 degrees), cos(C) is negative, making -2ab cos(C) positive. This means c2 = a2 + b2 + |2ab cos(C)|, resulting in c being longer than the Pythagorean distance. When angle C equals exactly 90 degrees, the cosine term vanishes and the formula becomes the Pythagorean theorem. When rearranging to find an angle, cos(C) = (a2+b2-c2)/(2ab), a negative result for cos(C) means the angle is obtuse, which is perfectly valid and indicates the triangle has one angle greater than 90 degrees.

References

Reviewed by Manoj Kumar, Mathematics Educator ยท Editorial policy