Mathematics

Pythagorean Theorem

a² + b² = c² — the most famous equation in geometry

The Pythagorean theorem says that for any right triangle, the square of the hypotenuse equals the sum of squares of the other two sides — a² + b² = c². It connects geometry to algebra, underlies the distance formula in any number of dimensions, and proves that √2 is irrational. Known to the Babylonians 1000 years before Pythagoras; first proved formally in Euclid's Elements around 300 BCE.

  • Equationa² + b² = c²
  • Applies toRight triangles only (one 90° angle)
  • Distance formula generalizationd = √(Σ (x_i − y_i)²) — Pythagoras in n dimensions
  • Number of known proofs~370 (largest collection of any theorem)
  • First written proofEuclid Book I, Proposition 47 (~300 BCE)
  • Earliest known useBabylonian tablets, ~1800 BCE (Plimpton 322)

Interactive visualization

Press play, or step through manually. The visualization is yours to drive — try it before reading on.

Open visualization fullscreen ↗

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

The theorem and its meaning

For a right triangle (one angle is exactly 90°) with legs of length a and b, and hypotenuse c (the side opposite the right angle):

a² + b² = c²

If you build squares outward from each side, the two squares on the legs have a combined area equal to the square on the hypotenuse. This is the geometric heart of the theorem.

Concrete example. A 3-4-5 triangle has legs 3 and 4, hypotenuse 5. Verify — 9 + 16 = 25. ✓ Builders use this as a quick way to check right angles — a triangle with sides 3, 4, 5 (or any multiple — 6, 8, 10) has a guaranteed 90° angle opposite the 5-side.

A few classic proofs

The rearrangement proof

Take a square of side a + b. Inside, arrange four copies of a right triangle with legs a, b and hypotenuse c, plus a smaller square. Do this two ways:

  1. Place the triangles in the corners with their hypotenuses inward — you get the c² square in the middle plus 4 triangles totaling 2ab. Total area — c² + 2ab.
  2. Place the triangles to leave an a² square and a b² square plus the same 4 triangles. Total area — a² + b² + 2ab.

Both equal (a + b)². Subtract 2ab — c² = a² + b². Done in three lines.

Euclid's proof (Book I, Proposition 47)

Drop a perpendicular from the right angle to the hypotenuse, splitting the original triangle into two smaller right triangles similar to the original. Use the similar-triangle proportions to show that the area of the square on each leg equals the rectangle formed on the hypotenuse — a 1:1 area decomposition. The full proof is 25 careful steps; Euclid called it the "windmill" proof for the diagram's shape.

Garfield's trapezoid proof

Future US President James Garfield published this in 1876. Build a right trapezoid from two copies of a right triangle plus the triangle on the hypotenuse. Compute the area two ways — as a trapezoid and as the sum of three triangles. Equate and simplify.

From Pythagoras to the distance formula

The distance between two points (x₁, y₁) and (x₂, y₂) in the plane is just Pythagoras applied to the right triangle with horizontal leg |x₂ − x₁| and vertical leg |y₂ − y₁|:

d = √((x₂ − x₁)² + (y₂ − y₁)²)

This generalizes directly to any number of dimensions. The Euclidean distance between two n-dimensional vectors is:

d = √(Σᵢ (xᵢ − yᵢ)²)

Modern machine learning uses this thousands of times per second — k-nearest-neighbors classifiers, embedding similarity, gradient norms. Every "distance" in any number of dimensions traces back to the right-triangle theorem.

Pythagorean triples

Triple (a, b, c)VerifyNotes
(3, 4, 5)9 + 16 = 25Smallest primitive; used by ancient builders
(5, 12, 13)25 + 144 = 169Common in geometry problems
(8, 15, 17)64 + 225 = 289From m=4, n=1 in Euclid's formula
(7, 24, 25)49 + 576 = 625From m=4, n=3
(20, 21, 29)400 + 441 = 841Almost-isosceles right triangle
(9, 40, 41)81 + 1600 = 1681From m=5, n=4

Every primitive triple (gcd = 1) has the form (m² − n², 2mn, m² + n²) for positive integers m > n with gcd(m, n) = 1 and one of them even. There are infinitely many; the smallest are listed above. Babylonian Plimpton 322 (~1800 BCE) lists 15 such triples, suggesting the formula was known three thousand years before Euclid.

When the theorem applies — and when it doesn't

  • Right triangles in flat (Euclidean) geometry. The theorem holds exactly.
  • Non-right triangles. Use the law of cosines — c² = a² + b² − 2ab·cos(C). Pythagoras is the special case C = 90°.
  • Curved space. On a sphere or in general relativity, distances don't follow the Euclidean formula. The metric tensor generalizes Pythagoras to arbitrary geometries.
  • Non-Euclidean geometries. In hyperbolic and elliptic geometries, the Pythagorean relation is replaced by hyperbolic and spherical analogs respectively. Pythagoras holds only in flat space.

JavaScript: distance functions

// 2D distance
function dist2D(x1, y1, x2, y2) {
  return Math.hypot(x2 - x1, y2 - y1);
}

// n-dimensional distance — most efficient form
function distND(a, b) {
  let sum = 0;
  for (let i = 0; i < a.length; i++) {
    const d = a[i] - b[i];
    sum += d * d;
  }
  return Math.sqrt(sum);
}

// Math.hypot is the numerically-stable version — avoids overflow on huge numbers
Math.hypot(3e200, 4e200);  // 5e200 — won't overflow
Math.sqrt(9e400 + 16e400); // Infinity — overflow

// Generate primitive Pythagorean triples up to limit
function* primitiveTriples(limit) {
  for (let m = 2; m * m <= limit; m++) {
    for (let n = 1; n < m; n++) {
      if ((m + n) % 2 !== 1) continue;  // exactly one even
      if (gcd(m, n) !== 1) continue;
      const a = m * m - n * n;
      const b = 2 * m * n;
      const c = m * m + n * n;
      if (c > limit) continue;
      yield [Math.min(a, b), Math.max(a, b), c];
    }
  }
}
function gcd(a, b) { return b ? gcd(b, a % b) : a; }

Why this theorem matters historically

  • Bridged geometry and algebra. First major result that translated a geometric statement (right triangles) into an algebraic one (sum of squares). Foundation for analytic geometry 2000 years later.
  • Established the irrational numbers. The diagonal of a unit square is √2 — provably not a ratio of integers. Greek mathematicians had assumed all numbers were rational; this discovery forced a complete reconception of "number."
  • Foundation for trigonometry. The unit circle, sine and cosine, and all trig identities rest on Pythagorean reasoning. sin²θ + cos²θ = 1 IS Pythagoras applied to the unit circle.
  • Defines distance in every metric space. Every "norm" in mathematics generalizes the Pythagorean idea. ℓ² norm, RMS, energy in physics, standard deviation — all use the sum-of-squares structure.
  • Calculus and physics. Velocity, acceleration, kinetic energy, gravitational/electric potential — all use distance, all rely on Pythagoras.

Common mistakes

  • Applying it to non-right triangles. Pythagoras requires a 90° angle. For other triangles, use the law of cosines.
  • Forgetting to take the square root. If c² = a² + b², then c = √(a² + b²). Beginners often stop at c² and call it "the answer."
  • Mixing up which side is the hypotenuse. The hypotenuse is always opposite the right angle and is always the longest side. The legs are the two sides adjacent to the right angle.
  • Numerical overflow on large values. Computing √(a² + b²) directly overflows for large a or b. Use Math.hypot(a, b) in JavaScript or math.hypot in Python — both implement a numerically stable version.
  • Confusing Pythagoras with the law of cosines. The general formula c² = a² + b² − 2ab·cos(C) reduces to Pythagoras when C = 90°. Memorize the general one; Pythagoras is the special case.
  • Assuming the converse without verification. If a² + b² = c², the triangle IS right-angled (converse holds). But sloppy applications check distances rather than computing squared sums; for non-Euclidean spaces or numerical-precision-limited contexts, the converse can mislead.

Frequently asked questions

Why does a² + b² = c² only work for right triangles?

It's the Pythagorean theorem precisely because it characterizes right angles. For non-right triangles, you need the law of cosines — c² = a² + b² − 2ab·cos(C). When C = 90°, cos(90°) = 0 and the law of cosines reduces to Pythagoras. So Pythagoras is just a special case of the more general law of cosines.

What's a Pythagorean triple?

Three positive integers (a, b, c) satisfying a² + b² = c². The smallest is (3, 4, 5) — 9 + 16 = 25. Other primitive triples (where gcd = 1) — (5, 12, 13), (8, 15, 17), (7, 24, 25), (20, 21, 29). Every primitive triple has the form (m² − n², 2mn, m² + n²) for coprime m &gt; n with one even. Babylonians knew dozens of these by 1800 BCE.

How does Pythagoras imply √2 is irrational?

A unit square has diagonal √2 (since 1² + 1² = 2 = c²). If √2 were rational (p/q in lowest terms), then 2q² = p². So p² is even → p is even → p = 2k → 4k² = 2q² → q² = 2k² → q is also even. But p/q was in lowest terms — contradiction. The Pythagoreans allegedly killed Hippasus for revealing this; the discovery shattered their belief that all numbers were rational ratios.

What's the distance formula in 2D and 3D?

In 2D, distance between (x₁, y₁) and (x₂, y₂) is √((x₂−x₁)² + (y₂−y₁)²) — directly Pythagoras with the differences as legs. In 3D, add a (z₂−z₁)² term. In n dimensions, sum n squared differences. Modern machine learning uses this generalized form constantly — Euclidean distance is the default similarity metric.

How many proofs of the Pythagorean theorem exist?

Around 370. Elisha Scott Loomis collected them in <em>The Pythagorean Proposition</em> (1940) — algebraic, geometric, dynamic, calculus-based. President James Garfield (yes, US president) published a novel proof in 1876. Loomis controversially noted that no trigonometric proof exists because trig identities themselves rely on the theorem — though in 2023 two New Orleans high-schoolers, Ne'Kiya Jackson and Calcea Johnson, presented a trigonometric proof anyway, sparking renewed debate.

Did Pythagoras actually prove it?

Probably not the way we mean. The theorem was known to Babylonians (Plimpton 322 tablet, ~1800 BCE), Indians (Sulba Sutras, ~800 BCE), and Egyptians (rope-stretching for right angles in pyramid construction). Pythagoras (~570-495 BCE) is credited because his school proved it deductively from axioms — but no original writings survive, so the historical attribution is fuzzy. The first surviving rigorous proof is Euclid's.

What's the geometric intuition?

Build squares on each of the three sides. The two smaller squares have area a² and b²; the square on the hypotenuse has area c². The theorem says: combined area of the two smaller squares equals area of the largest. Visual proofs show literally fitting the two small squares into the big one — by cutting and rearranging.