Pythagorean Triples

(3, 4, 5) and (5, 12, 13) are both whole-number side lengths of a right triangle: 3^2+4^2=5^2 and 5^2+12^2=13^2, no fractions, no approximations, exact. These are called Pythagorean triples. The obvious question is whether there are more of them out there — a handful, a few hundred, or truly endlessly many — and whether anyone has ever found a single formula that spits out every one on demand, instead of hunting for them by trial and error.

The answer to both is yes, and the formula is astonishingly simple — three small expressions built from just two whole numbers. Finding it, and proving it really does capture every triple with none left over, is one of the oldest solved problems in all of mathematics.

a^2 + b^2 = c^2.

Finding all whole-number solutions is a classic Diophantine problem — and unlike most such problems, this one has a complete, beautiful answer that we can write down in full.

This is not just an abstract curiosity, either. Long before anyone had a formula, builders and surveyors used the 345 triple as a tool: knot a rope into twelve equal loops, stretch it into a triangle with sides of 3, 4, and 5 loops, and the angle between the two short sides is guaranteed to be a perfect right angle — no protractor required. Egyptian "rope-stretchers" are said to have used exactly this trick to re-mark field boundaries after the Nile's floods, and carpenters still use the same 3-4-5 rule today to square up a wall or a deck.

Primitive triples

Scaling a triple gives another: double every side of (3,4,5) and (6,8,10) is still a Pythagorean triple, since (2a)^2+(2b)^2 = 4(a^2+b^2) = 4c^2 = (2c)^2. Multiply by any whole number k and the same trick works. So the "new" triples worth hunting for are the ones that aren't just an old triple scaled up — the primitive triples, where a, b, c share no common factor (gcd (a,b,c) = 1). Every triple, without exception, is some primitive triple scaled up by a whole number — so finding all the primitives is exactly the same job as finding everything.

Euclid's complete formula

Every primitive Pythagorean triple (with b even) is given, for coprime m > n > 0 of opposite parity, by

a = m^2 - n^2, \qquad b = 2mn, \qquad c = m^2 + n^2.

Every choice of such m, n gives a primitive triple, and every primitive triple arises this way for exactly one such pair.

This shows up in Euclid's Elements, more than two thousand years old, and it is a complete answer: two whole numbers, three arithmetic expressions, and the entire infinite family of primitive right triangles falls out.

Worked examples

Example 1 — the smallest case. Try the smallest legal seed, m = 2, n = 1 (coprime, and opposite parity: one even, one odd):

a = 2^2-1^2 = 3, \qquad b = 2(2)(1) = 4, \qquad c = 2^2+1^2 = 5.

Out pops (3, 4, 5) — the very first triple, generated from nothing but the pair (2,1).

Example 2 — a bigger one. Step up to m = 3, n = 2 (also coprime, also opposite parity):

a = 3^2-2^2 = 5, \qquad b = 2(3)(2) = 12, \qquad c = 3^2+2^2 = 13.

That's (5, 12, 13) — a completely different, bigger triangle, produced by the exact same three formulas, just fed a different seed. Push on to m=4,n=1 and you get (15, 8, 17); to m=4,n=3 and you get (7, 24, 25). Two small numbers in, one exact right triangle out, every time. Laid out side by side, the pattern is hard to miss:

mna=m^2-n^2b=2mnc=m^2+n^2
21345
3251213
4115817
4372425
52212029
5494041

Six different seeds, six completely different right triangles, none of them a scaled copy of another — and the table could keep going forever, since there's no limit on how large a coprime, opposite-parity pair (m,n) can be.

Example 3 — checking it algebraically, not just numerically. Rather than trusting the pattern from a handful of examples, expand the formula in full generality and see the identity fall out on its own:

(m^2-n^2)^2 + (2mn)^2 = (m^4 - 2m^2n^2 + n^4) + 4m^2n^2 = m^4 + 2m^2n^2 + n^4 = (m^2+n^2)^2.

The middle terms -2m^2n^2 and +4m^2n^2 combine to +2m^2n^2, landing exactly on the expansion of (m^2+n^2)^2. This holds for every choice of m and n whatsoever — it's not a numerical coincidence checked case by case, it's an algebraic identity, true by the rules of expanding brackets alone.

Where the formula comes from: a detour through complex numbers

Euclid's formula can be derived by pure algebra (completing a clever substitution), but the slickest route runs through complex numbers. Rewrite the equation as

a^2 + b^2 = (a+bi)(a-bi) = c^2,

working inside the Gaussian integers \mathbb{Z}[i], numbers of the form a+bi with a,b whole. That number system also enjoys unique factorisation into primes, so — for a primitive triple — the fact that (a+bi)(a-bi) is a perfect square forces a+bi itself to be (up to a unit) a perfect square of some Gaussian integer: a + bi = (m+ni)^2. Expand the right side —

(m+ni)^2 = (m^2-n^2) + (2mn)i,

match real and imaginary parts, and Euclid's formula appears without ever guessing it. The same Gaussian-integer machinery, pushed a little further, is exactly what tells us which numbers can be written as a sum of two squares in the first place.

Check it against the very first example: m=2, n=1 corresponds to the Gaussian integer 2+i. Squaring it directly,

(2+i)^2 = 4 + 4i + i^2 = 4 + 4i - 1 = 3 + 4i,

and reading off the real and imaginary parts gives a=3, b=4 — the (3,4,5) triple again, reached this time by squaring a single complex number instead of plugging into two separate formulas.

A geometric retelling

Dividing by c^2 turns the equation into (a/c)^2 + (b/c)^2 = 1 — so primitive triples are exactly the rational points on the unit circle. Drawing lines of rational slope from the fixed point (-1, 0) hits every such point exactly once, which is yet another way to derive Euclid's formula, this time by pure geometry rather than algebra or complex numbers. This "rational points on a curve" viewpoint is the seed of modern arithmetic geometry — and it makes the contrast with Fermat's Last Theorem (no such whole-number solutions at all once the exponent rises from 2 to 3 or higher) all the more striking.

The formula always produces a Pythagorean triple for any m > n > 0 — but it only produces a primitive one when m and n are coprime and of opposite parity (one even, one odd). Skip either condition and the formula still works, but hands you a scaled-up multiple of a smaller triple in disguise.

Only coprime, opposite-parity pairs are guaranteed to produce a genuinely new primitive triple — and every primitive triple traces back to exactly one such pair.

By about 3,500 years. A clay tablet catalogued as Plimpton 322, dug up in Mesopotamia and dated to roughly 1800 BCE, lists row after row of Pythagorean triples — some with numbers in the thousands — written in Babylonian base-60 cuneiform. That's over a millennium before Pythagoras (or whoever in his school actually proved the theorem) was even born.

Nobody is entirely sure how the Babylonian scribes generated such large, accurate triples without algebra as we know it today — leading historians to suspect they had stumbled on some version of the very same generating idea behind Euclid's formula, worked out by careful arithmetic rather than symbols. One row of the tablet lists the triple (13500, 12709, 18541) — numbers far too large to stumble on by randomly trying right triangles, and a clear sign of a systematic method rather than luck. A formula that looks thoroughly modern turns out to have unimaginably ancient roots.

See it explained