A triangle is defined by six measurements: three sides and three angles. If you know any two sides and the angle sitting between them, you can find the remaining side with one calculation. The law of cosines — often called the cosine rule — does exactly that, and this calculator turns the formula into instant results. Type in sides a and b and the included angle C, and the missing side c appears immediately, along with the triangle's area, perimeter, and the angle opposite side a.
The law of cosines is the general case of the Pythagorean theorem. When angle C is exactly 90 degrees, the cosine term drops out and you are left with the familiar c² = a² + b². For every other angle, the formula adjusts that right-triangle relationship, which is why it works on acute, obtuse, and flat triangles alike.
How to Use
- Enter Side a — one of the two known sides that touches the included angle. The units can be anything (meters, feet, centimeters) as long as both sides use the same unit.
- Enter Side b — the other known side that touches the same angle.
- Enter the Included Angle C in degrees. This is the angle between sides a and b, directly opposite the side you want to find. It must be between 0 and 180 degrees.
- Read Missing Side c on the result card. The calculator also returns the Triangle Area, the Perimeter, and Angle A (the angle opposite side a).
Because the result depends only on the relative lengths, it does not matter whether you measure in feet or meters — the answer comes out in the same unit you typed. If the angle is close to 90 degrees, expect the result to land within a fraction of a percent of the Pythagorean distance; if the angle is obtuse (greater than 90), side c grows noticeably longer.
The Cosine Rule Formula
The law of cosines reads:
c² = a² + b² − 2ab·cos(C)
Where:
- c is the unknown side opposite angle C.
- a and b are the two known sides.
- C is the angle between sides a and b, measured in degrees.
To get c itself, take the square root: c = √(a² + b² − 2ab·cos(C)). The calculator first converts the angle from degrees to radians (most programming languages and spreadsheets expect radians for cosine), then applies the formula. Once c is known, the area follows from the side-angle-side rule Area = ½·a·b·sin(C), and the perimeter is simply a + b + c.
A quick sanity check: with a = 3, b = 4, and C = 90°, we get c² = 9 + 16 − 24·cos(90°) = 25, so c = 5. That is the classic 3-4-5 right triangle, which confirms the formula reduces to Pythagoras when the angle is 90 degrees.
Examples
Example 1 — The 3-4-5 check. Sides 3 and 4 meet at a 90° angle. The missing side is exactly 5, the area is 6, and the perimeter is 12. This is the default value set on the page so you can verify the tool against the Pythagorean theorem.
Example 2 — A non-right triangle. Two sides of 5 and 7 units meet at a 60° angle. Since cos(60°) = 0.5, c² = 25 + 49 − 70·0.5 = 39, so c ≈ 6.25 units. The area is about 15.16 and the perimeter is roughly 18.25 units. This is the case where the cosine term actually matters — the Pythagorean theorem would give 8.6, which is wrong.
Example 3 — Land surveying. A builder measures two edges of a triangular lot as 100 feet and 140 feet, meeting at an angle of 110°. The unseen property line is c = √(100² + 140² − 2·100·140·cos(110°)) ≈ 201.5 feet. Knowing that distance keeps the contractor from ordering roughly 20% too little fencing material.
Example 4 — Very large sides. Enter 1,000,000 and 1,000,000 with a 60° angle, and the calculator returns a side c of 1,000,000 — an equilateral triangle where every side matches, and the perimeter is 3,000,000. The engine handles these magnitudes without overflow.
FAQ
What is the law of cosines?
It is the formula c² = a² + b² − 2ab·cos(C), used to find the third side of a triangle when you know two sides and the included angle. It generalizes the Pythagorean theorem to triangles that are not right-angled.
When should I use the law of cosines instead of the Pythagorean theorem?
Use the Pythagorean theorem only when the triangle contains a 90° angle. Whenever the included angle is anything else — acute or obtuse — use the law of cosines, because the 2ab·cos(C) correction term is no longer zero.
Does the angle have to be in degrees?
This calculator takes the angle in degrees between 0 and 180. Internally it converts to radians before applying cosine, which is the convention used by spreadsheets and most math libraries.
What happens if the included angle is 0 or 180 degrees?
At 0° the two known sides point the same way, so the missing side equals their difference; with a = 3 and b = 4, c = 1. At 180° they point opposite ways, so c equals their sum. These are degenerate "flat" triangles with zero area, but the formula still gives a stable answer.
Can I use this to find an angle instead of a side?
Yes. Rearranged, the law says cos(C) = (a² + b² − c²) / (2ab), so if you know all three sides you can solve for any angle with arccosine. This is often called the SSS (side-side-side) case.
What is the difference between SAS and SSS?
SAS (side-angle-side) is when you know two sides and the angle between them — the direct input of this calculator. SSS (side-side-side) is when you know all three sides and want an angle. Both are solved with the same formula, just rearranged.
Can the law of cosines give a negative number under the square root?
Only if your inputs are physically impossible — for example a triangle inequality violation where one proposed side is longer than the other two combined. The result under the root is always non-negative for a valid triangle, and the calculator rejects negative side lengths.
Disclaimer
This law of cosines calculator is provided for informational purposes only and is intended for education, geometry homework, and rough estimation. It does not constitute engineering, surveying, or professional advice. Results are computed directly from the formula c² = a² + b² − 2ab·cos(C) using the values you enter; always double-check critical measurements in the field and consult a qualified professional before making real-world construction or design decisions.