Law of Cosines Calculator
Solve a triangle from SAS or SSS data and get the missing side, all three angles and the area.
What it does
The law of cosines relates the three sides of any triangle to one of its angles. OpenStax presents it as a generalized Pythagorean theorem: when the angle is 90 degrees the cosine term is zero and the familiar a squared plus b squared equals c squared is left. For every other angle the extra term corrects for the tilt between the two known sides.
Two situations call for it. In SAS you know two sides and the angle between them and want the opposite side. In SSS you know all three sides and want the angles. The law of sines handles other cases but cannot start from either of these, which is why this relation is the standard next tool in a trigonometry course.
The formula comes in three rotations, one for each side, and in a rearranged version that solves for an angle. Using arccosine rather than arcsine keeps the answer steady when an angle is close to 0 or 180 degrees, and it avoids the ambiguous second triangle that can appear with the law of sines.
This page accepts both SAS and SSS data. Give two sides and the included angle to get the missing side, the other two angles, the area and a check that the angles sum to 180 degrees. Give three sides to get all three angles and the area by Heron's formula. Angles are entered and shown in degrees.
The inputs are ordinary plane geometry lengths and angles, so no unit selector is needed. Any consistent length unit works: metres, feet or pixels all give the same angles, and the area comes out in square units of whatever you chose. The triangle has to be possible, so three sides entered for SSS must pass the triangle inequality.
How to use
- Pick the mode that matches what you know: SAS for two sides and the included angle, or SSS for three sides.
- In SAS mode enter the two known sides and the angle between them in degrees.
- In SSS mode enter the three side lengths. They must satisfy the triangle inequality.
- Read the main answer first: the missing side in SAS mode, or the angle opposite the third side in SSS mode.
- Read the two other angles and the area beneath it, then confirm the angle sum reads 180 degrees.
- Change one value to see how the triangle responds without re-entering the rest.
Formula
- a
- One known side, in any consistent length unit.
- b
- The other known side adjacent to the included angle.
- C
- The included angle between sides a and b, in degrees.
- c
- The side opposite angle C, which is the unknown in SAS mode.
- A
- The angle opposite side a, found with the rearranged form.
The included angle is the one touching both known sides. If your angle sits opposite a known side instead, use the law of sines or rearrange a different rotation of the formula. In SSS mode the page checks the triangle inequality first, because sides such as 1, 2 and 10 cannot close into a triangle. Cosines are clamped to the range minus one to one before the arccosine, which protects the result from tiny rounding overshoots.
Worked example
Example: sides 8 and 15 with an included angle of 60 degrees
Defaults: SAS mode, a = 8, b = 15 and C = 60 degrees.
- Start with c squared = a squared + b squared minus 2ab cos C = 64 + 225 minus 2 x 8 x 15 x cos 60.
- Since cos 60 = 0.5, the product term is 2 x 8 x 15 x 0.5 = 120, so c squared = 289 minus 120 = 169.
- Take the square root: c = 13. The main answer reads c = 13.
- Angle A: cos A = (225 + 169 minus 64)/(2 x 15 x 13) = 330/390 = 0.846154, so A = 32.2 degrees.
- Angle B: cos B = (64 + 169 minus 225)/(2 x 8 x 13) = 8/208 = 0.038462, so B = 87.8 degrees.
- Check: 32.2 + 87.8 + 60 = 180 degrees. Area = half x 8 x 15 x sin 60 = 51.96 square units.
Reference table
| Included angle C | Third side c | Area (square units) |
|---|---|---|
| 30 degrees | 9.009 | 30 |
| 60 degrees | 13 | 51.96 |
| 90 degrees | 17 | 60 |
| 120 degrees | 20.224 | 51.96 |
Limits
- Works in a flat plane only. Triangles drawn on a sphere need a different relation.
- Angles must be entered in degrees here. Radian values have to be converted first.
- Rounding each angle to one decimal place can make the displayed sum differ from 180 by a tenth of a degree.
- Returns side lengths and angles, not the position or orientation of the triangle in the plane.
Common mistakes
- Using the angle opposite a known side instead of the angle between the two known sides in SAS mode.
- Entering an angle in radians while the page expects degrees.
- Taking a square root too early and losing precision before the final step.
- Ignoring the triangle inequality in SSS mode and trusting an answer from impossible sides.
- Treating the area as fixed when it actually changes with the included angle.
Try it yourself
Quick checks. Answers sit tucked under each question.
Two sides are 6 and 10 with a 120 degree included angle. What is the third side?
c squared = 36 + 100 minus 2 x 6 x 10 x cos 120 = 136 + 60 = 196, so the third side is 14. The tool reports c = 14, A = 21.8 degrees, B = 38.2 degrees and area 25.98.
A triangle has sides 5, 7 and 10. Find its largest angle.
The largest side 10 faces the largest angle C. cos C = (25 + 49 minus 100)/(2 x 5 x 7) = minus 0.371429, giving 111.8 degrees. The tool reports C = 111.8 degrees, A = 27.7 degrees and B = 40.5 degrees.
Sides 8, 15 and 13 are entered in SSS mode. Which angle is largest and how big is it?
The largest side 15 faces the largest angle B. cos B = (64 + 169 minus 225)/(2 x 8 x 13) = 8/208 = 0.038462, so B = 87.8 degrees. The tool reports B = 87.8 degrees and area 51.96.
Questions
When should I use the law of cosines instead of the law of sines?
Use it for SAS and SSS, where the law of sines has no starting pair. The law of sines is quicker for ASA, AAS and the ambiguous SSA case.
Does the formula work for right triangles?
Yes. At 90 degrees cos C is zero, so c^2 = a^2 + b^2 and Pythagoras drops out as a special case.
What is the included angle?
The angle where the two known sides meet. It must sit between them, not across the triangle from either one.
Why is arccosine used for the angles?
It returns one value between 0 and 180 degrees, so there is no ambiguous second triangle and the result stays steady near a straight angle.
Can the third side be longer than both known sides?
Yes, when the included angle is obtuse. With a = 8, b = 15 and C = 120 degrees the third side is 20.224, longer than either input side.
What if the three sides do not form a triangle?
The page rejects them. Sides 1, 2 and 10 fail the triangle inequality because 1 + 2 is not greater than 10, and no triangle can be built.
Sources
- OpenStax Precalculus 2e, section 8.2: Non-right Triangles, Law of Cosines
- Mathematics LibreTexts, section 8.02: Non-right Triangles, Law of Cosines
- Western Washington University, Math 304: Law of cosines