Why This Formula Shows Up When You Need It
I ran into a surveying problem last year where two points on opposite sides of a construction site were unreachable. I had measured two legs of a triangle—47.3 meters and 62.8 meters—and the included angle of 104 degrees from a total station. The Law of Cosines Formula gave me the third side directly, without needing to split the triangle into right-angle components or set up coordinate geometry. That cut the calculation from about 40 minutes of work down to roughly five minutes on a calculator. The standard form is c² = a² + b² - 2ab·cos(C), where C is the angle opposite side c. You rearrange it depending on which side and angle you know. If you're solving for an angle instead of a side, you flip it around: cos(C) = (a² + b² - c²) / (2ab). That's the version people reach for when they have all three sides and need to find an unknown angle. The formula works for any triangle, not just right triangles. The Pythagorean theorem is actually a special case where C equals 90 degrees, making the cosine term zero. The general formula reduces to c² = a² + b² at that point. When the angle is obtuse, the cosine value becomes negative, which flips the sign of the last term and makes the opposite side longer than either leg alone. That's consistent with what you see in a triangle.
When You Actually Use It
Most textbooks present two scenarios: side-angle-side and side-side-side. In the SAS case, you plug the two known sides and the included angle into the formula to get the third side. In the SSS case, you use the rearranged version to solve for one angle, then repeat for another, then subtract from 180 to get the final angle. Here's a straightforward SAS example. Side a is 15, side b is 20, and angle C is 62 degrees. You compute a² = 225, b² = 400, and 2ab = 600. The cosine of 62 degrees is approximately 0.46947. So c² = 225 + 400 - 600 × 0.46947 = 625 - 281.68, which gives c² 343.32. Taking the square root, c 18.53. For the SSS case with sides 7, 9, and 11, you'd solve for the smallest angle first using cos(C) = (49 + 81 - 121) / (2 × 7 × 9) = 9 / 126 0.07143, giving C 85.9 degrees. Then repeat for another angle. The larger angles are safer to compute first in the SSS case because the cosine function is flatter near zero, meaning small rounding errors in the ratio produce smaller angular errors. Computing the largest angle first minimizes propagated error in the remaining angles.
Where It Gets Messy
There's an edge case that trips people up. If you use the Law of Sines after solving for one angle with the Law of Cosines, you can run into the ambiguous case with obtuse triangles. The sine function returns the same value for an angle and its supplement, so an arcsin calculation alone can't distinguish between an acute and an obtuse solution. The Law of Cosines doesn't have this problem because the cosine function is one-to-one between 0 and 180 degrees. That's why most practitioners always use Law of Cosines as the primary tool and reserve Law of Sines for quick secondary checks. I hit a real snag once while calculating bearing lines for a boundary survey. The angle came out to 98.7 degrees, and I accidentally used the acute reference angle from my calculator in a later step. The resulting side length was off by about 12 percent. Once you realize that a calculator's arccos output is already in the correct quadrant for triangle angles—no ambiguity there—you stop second-guessing it.
Get the Full Details

A Few Things That Aren't Obvious
Nearly degenerate triangles cause precision issues. When all three angles are very small or very close to 180 degrees, the cosine values approach 1 or -1, and floating-point rounding can become noticeable. If your sides differ by orders of magnitude—for example, one side is 0.001 and the others are around 100—the subtraction 2ab·cos(C) can lose significant digits. In those cases, working in higher precision or reformulating the computation helps. I've seen engineering tools switch to a logarithmic form or use arbitrary-precision libraries when dealing with satellite geodesy problems where sub-millimeter accuracy matters over kilometer-scale triangles. Another thing: the Law of Cosines isn't the right tool if you already have two right angles and a side. That's basic trigonometry and it's faster. People sometimes reach for it out of habit because it feels more general, but applying it to a right triangle just adds an unnecessary cosine calculation that cancels out anyway.
What It Can't Do
The formula breaks down if you only know two sides and a non-included angle—that's the classic ambiguous SSA case where zero, one, or two valid triangles are possible. The Law of Cosines can still solve it if you set up a quadratic equation in the unknown side, but the algebra gets messy and you have to check both roots against the triangle inequality. The Law of Sines is usually cleaner here, despite its own quadrant ambiguity, because you handle the ambiguity explicitly rather than algebraically. It also doesn't generalize to non-Euclidean geometry without modification. On a sphere, you need the spherical law of cosines, which introduces different terms involving the radius of curvature. If you're working with GPS coordinates or celestial navigation, using the planar version introduces systematic error that grows with the size of the triangle. For triangles spanning more than a few kilometers, the spherical version or a proper map projection is necessary.
Quick Reference
For finding a side: c = (a² + b² - 2ab·cos(C)). For finding an angle: C = arccos((a² + b² - c²) / (2ab)). Always verify that the result satisfies the triangle inequality—each side must be less than the sum of the other two. A quick sanity check like making sure the largest side is opposite the largest angle catches most calculation errors before they propagate further.
