Skip to content

← Math Further 9–12

How Do You Find Every Right Triangle with Whole Sides?

Topic 7 · Grades 9–12 · Pythagorean triples

What this builds on from class
In this unit 11 sections
  1. Hunt for triangles
  2. Bend the square into an L
  3. A recipe that makes them all
  4. Why the recipe misses none
  5. Every triple is a point on a circle
  6. Harder puzzles of the same kind
  7. Where the rule breaks
  8. Who found the recipe?
  9. Where this is used
  10. Questions
  11. Where to go next

A mistri laying out a new classroom in Bhaktapur has no set square big enough for a room. So he does what builders everywhere do: from the corner he marks 3 meters along one wall line and 4 meters along the other, and moves the second line until the two marks are exactly 5 meters apart. Then the corner is square, because 3² + 4² = 5², and all three are whole numbers, easy to read off a tape.

The hall is long, so he wants a side of 12 meters, with the other two sides whole numbers too. Try it: set one short side to 12 and look for another that makes the long side whole.

Try it

Hunt for right triangles with whole sides

Choose the two short sides, a and b. The long side is worked out by Pythagoras: c=a2+b2 c = \sqrt{a^2 + b^2} . When it comes out a whole number, the triangle goes on your list. The empty boxes are the ones still to find with both short sides 40 or less.

20a = 12b = 8c = 14.422…
a² + b²
144 + 64 = 208
Long side c = √208
14.422…

Not whole: no whole number squared makes this.

A whole-number right triangle! It goes on your list.

Whole, but you have this one already.

Found with both short sides up to 40: 0 of 19

  1. 3, 4, 5
  2. 5, 12, 13
  3. 6, 8, 10
  4. 7, 24, 25
  5. 8, 15, 17
  6. 9, 12, 15
  7. 9, 40, 41
  8. 10, 24, 26
  9. 12, 16, 20
  10. 12, 35, 37
  11. 15, 20, 25
  12. 15, 36, 39
  13. 16, 30, 34
  14. 18, 24, 30
  15. 20, 21, 29
  16. 21, 28, 35
  17. 24, 32, 40
  18. 27, 36, 45
  19. 30, 40, 50

Guess first. How many right triangles with whole-number sides have a short side of 12?

Pick an answer to see why.

Hunt for triangles

Spend a few minutes with the hunt above. Try these, in order.

  • a.Find all four triangles with a short side of 12.
  • b.Find 6, 8, 10 and 9, 12, 15. How are they related to 3, 4, 5?
  • c.Find a triangle on your list that is not a bigger copy of a smaller one.
  • d.Look at 3, 4, 5, then 5, 12, 13, then 7, 24, 25. What do the long side and the middle side always do? Predict the next one, starting from 9, and check it.

A right triangle with whole-number sides is a Pythagorean triangle, and its three numbers a Pythagorean triple. A triple whose numbers have no common factor, like 3, 4, 5, is a primitive triple; every other triple is a primitive one multiplied up. So the real hunt is for the primitive ones.

Bend the square into an L

Here is the idea that finds every triangle with a given side. Write the rule with the known side a on its own:

a2=c2−b2 a^2 = c^2 - b^2

Picture it. c2 c^2 is a square of side c. Take out a square of side b from one corner and what is left is an L of width c − b. So the rule says: the a2 a^2 small squares of a square of side a can be rearranged into an L that fits round a square of side b.

The L’s area is easy to count. Cut it at the corner and lay its two arms end to end: a strip c − b wide and c + b long. So

a2=c2−b2=(c−b)(c+b) a^2 = c^2 - b^2 = (c - b)(c + b)

which is the difference of two squares from Grade 9’s factorization, now with a job to do. For 5, 12, 13: 52=25=(13−12)(13+12)=1×25 5^2 = 25 = (13 - 12)(13 + 12) = 1 \times 25 . The L is one square wide.

Try it

Bend a square into an L

On the left, the square of the side you know, a. On the right, an L of width d with exactly the same area, wrapped round a square of side b. The L always fits; the question is whether b and c come out whole. Start with a = 12 and try every width from 1 to 11.

a = 12a² = 144=b = 5c = 13d = 8
a² ÷ d
144 ÷ 8 = 18
b = (a² ÷ d − d) ÷ 2
5
c = b + d
13

Whole numbers: the triangle 12, 5, 13 has a right angle, because the L holds exactly 144 squares.

The L still fits, but 8 doesn’t divide 144, so its long sides aren’t whole.

8 divides 144, but 18 − 8 is odd, so b ends in .5 and isn’t whole.

So to find every triangle with a short side of 12, write 144 = d × e with d = c − b the smaller factor and e = c + b the larger. Then c and b are the half-sum and half-difference:

c=e+d2,b=e−d2 c = \frac{e + d}{2}, \qquad b = \frac{e - d}{2}

For these to be whole, d and e must both be even or both odd.

This is how Bhaskara did it in the Lilavati (1150 AD). In Colebrooke’s 1817 translation: “a side is put. Its square, divided by an arbitrary number, is set down in two places: and the arbitrary number being added and subtracted, and the sum and difference halved, the results are the hypotenuse and upright.” His example is the side 12: with the arbitrary number 2 he gets 35, 37, then 16, 20 and 9, 15. His commentator Ganesa says why it works: “the difference of the squares is equal to the product of the sum and difference of the roots.”

A recipe that makes them all

The L finds the triangles with one side you know. To make every triangle, start from two numbers instead. Take any whole numbers p > q, and make

a=p2−q2,b=2pq,c=p2+q2 a = p^2 - q^2, \qquad b = 2pq, \qquad c = p^2 + q^2

With p = 2, q = 1: 3, 4, 5. With p = 3, q = 2: 5, 12, 13. With p = 5, q = 2: 21, 20, 29, the triangle from the card on this topic. The table shows more.

q = 1 q = 2 q = 3 q = 4 q = 5
p = 2 3, 4, 5
p = 3 8, 6, 10 5, 12, 13
p = 4 15, 8, 17 12, 16, 20 7, 24, 25
p = 5 24, 10, 26 21, 20, 29 16, 30, 34 9, 40, 41
p = 6 35, 12, 37 32, 24, 40 27, 36, 45 20, 48, 52 11, 60, 61

Why must it always work? Not because the table’s fifteen cases check out: because the rule is an identity, true for every p and q. Expand both sides.

(p2−q2)2+(2pq)2=p4−2p2q2+q4+4p2q2=p4+2p2q2+q4=(p2+q2)2 (p^2 - q^2)^2 + (2pq)^2 = p^4 - 2p^2q^2 + q^4 + 4p^2q^2 = p^4 + 2p^2q^2 + q^4 = (p^2 + q^2)^2

The −2p2q2 -2p^2q^2 from the first square and the 4p2q2 4p^2q^2 from the second leave +2p2q2 +2p^2q^2 , exactly what (p2+q2)2 (p^2 + q^2)^2 has in its middle. Since it holds for all numbers, any p > q gives a right triangle with whole sides, and there are infinitely many p and q, so infinitely many triangles that aren’t copies of each other. This recipe is usually called Euclid’s formula, after the Elements, about 300 BC.

The L is hiding inside it too: c−b=p2+q2−2pq=(p−q)2 c - b = p^2 + q^2 - 2pq = (p - q)^2 and c+b=(p+q)2 c + b = (p + q)^2 . The L’s width and length are both squares.

Which pairs p, q in the table gave a triple that is only a copy of a smaller one?

Pick an answer to see why.

Why the recipe misses none

The table makes infinitely many triangles. But does it make all of them? Perhaps some strange primitive triple with sides in the millions isn’t in it. Here is why that can’t happen. Take any primitive triple a, b, c.

1. One short side is even, the other odd. They can’t both be even, or all three would share the factor 2. They can’t both be odd either. Divide any square by 4 and look at the remainder: an even number squared, (2k)2=4k2 (2k)^2 = 4k^2 , leaves 0; an odd number squared, (2k+1)2=4k2+4k+1 (2k + 1)^2 = 4k^2 + 4k + 1 , leaves 1. Two odd squares added leave 2, and no square leaves 2. So exactly one short side is even; call it b. Then c is odd.

2. Split the L. b2=(c−a)(c+a) b^2 = (c - a)(c + a) , and c and a are both odd, so c − a and c + a are both even. Write c + a = 2m and c − a = 2n. Then b2=4mn b^2 = 4mn , so mn=(b/2)2 mn = (b/2)^2 , a perfect square, with c = m + n and a = m − n.

3. m and n share no factor. Anything that divides both divides m + n = c and m − n = a too. And a and c share no prime: one that divided both would divide c2−a2=b2 c^2 - a^2 = b^2 , so b as well, and the triple wouldn’t be primitive.

4. So each of them is a square. Every whole number splits into primes in only one way. In a perfect square each prime comes an even number of times (36 = 2 × 2 × 3 × 3). Here m and n share no prime, so all the 2s of mn belong to one of them, all the 3s to one of them, and so on, each prime with its even count. So m is a square, p2 p^2 , and n is a square, q2 q^2 .

Put them back: c=m+n=p2+q2 c = m + n = p^2 + q^2 , a=m−n=p2−q2 a = m - n = p^2 - q^2 , and b=2mn=2pq b = 2\sqrt{mn} = 2pq . Since m and n share no factor, neither do p and q; since c=p2+q2 c = p^2 + q^2 is odd, one of them is even. That is the recipe. Every primitive triple is in the table; every other triple is a primitive one times a whole number.

Every triple is a point on a circle

There is a picture of all of this at once. Divide a2+b2=c2 a^2 + b^2 = c^2 by c2 c^2 :

(ac)2+(bc)2=1 \left(\frac{a}{c}\right)^2 + \left(\frac{b}{c}\right)^2 = 1

So the point (a/c,  b/c) lies on the circle x2+y2=1 x^2 + y^2 = 1 (Grade 10 Optional Math, the circle), and it is a point whose coordinates are both fractions. 3, 4, 5 is the point (3/5,  4/5). Finding Pythagorean triples is the same as finding the points on the circle with fractions for coordinates.

The way to find those points is a line. Start at the point (−1, 0) on the circle and draw a line with a fraction for its slope, q/p: up q for every p across. It meets the circle in one more point, and that point turns out to have fractions for coordinates too.

Try it

A line with a fraction for its slope

Choose p and q: the line from (−1, 0) goes up q for every p across. Where it meets the circle again, the point’s coordinates are fractions over p2+q2 p^2 + q^2 , and multiplying them by p2+q2 p^2 + q^2 gives a triple. Find 20, 21, 29.

11(−1, 0)xy
Slope
2/3
The point (x, y)
(5/13, 12/13)
Times 13: the triangle
5, 12, 13

A new triangle: its three sides have no common factor.

p and q are both odd, so every side is even: halved, it is 5, 12, 13.

p and q share a factor, so this is a copy of 5, 12, 13, made bigger.

Hint
Answer

Why fractions? Write t = q/p for the slope, so the line is y = t(x + 1). Put it into x2+y2=1 x^2 + y^2 = 1 , in the form (x2−1)+y2=0 (x^2 - 1) + y^2 = 0 :

(x−1)(x+1)+t2(x+1)2=0⟹(x+1)[(x−1)+t2(x+1)]=0 (x - 1)(x + 1) + t^2(x + 1)^2 = 0 \quad\Longrightarrow\quad (x + 1)\bigl[(x - 1) + t^2(x + 1)\bigr] = 0

The factor x + 1 is the point we started from, x = −1. The other point makes the bracket 0: x(1+t2)=1−t2 x(1 + t^2) = 1 - t^2 , so x=(1−t2)/(1+t2) x = (1 - t^2)/(1 + t^2) , a fraction, with no square root anywhere. Put t = q/p and multiply top and bottom by p2 p^2 :

x=p2−q2p2+q2,y=2pqp2+q2 x = \frac{p^2 - q^2}{p^2 + q^2}, \qquad y = \frac{2pq}{p^2 + q^2}

the recipe again. And every point with fractions for coordinates is reached this way, since the line from (−1, 0) to it has a fraction for its slope. Diophantus of Alexandria, in the third century AD, used the same trick in numbers (a line through a point he already knew) to split a square into two squares in his Arithmetica (Book II, Problem 8): his example splits 16 into (16/5)2+(12/5)2 (16/5)^2 + (12/5)^2 , which is 3, 4, 5 again, times 4/5.

Harder puzzles of the same kind

The recipe answers questions that would be hopeless by hunting.

Which numbers can be a side? Every whole number from 3 up. An odd number n is in n, (n2−1)/2, (n2+1)/2 n,\ (n^2 - 1)/2,\ (n^2 + 1)/2 , the family you found (p and q one apart). A multiple of 4, 4k, is in 4k, 4k2−1, 4k2+1 4k,\ 4k^2 - 1,\ 4k^2 + 1 (p = 2k, q = 1). The numbers left over, 6, 10, 14, 18…, are twice an odd number: the even side of a primitive triple is 2pq with one of p, q even, so a multiple of 4, and these numbers can only appear in copies, like 6, 8, 10 or 14, 48, 50.

Which numbers can be the long side? Among the primitive triples up to 100 the long sides are 5, 13, 17, 25, 29, 37, 41, 53, 61, 65, 73, 85, 89 and 97. Each leaves 1 when divided by 4, as the recipe says it must: p2+q2 p^2 + q^2 is an odd square (remainder 1) plus an even one (remainder 0). But 9, 21, 33, 45, 49, 57, 69, 77, 81 and 93 also leave 1, and none is ever the long side of a primitive triple. Their trouble is a prime factor (3, 7, 11, 19, 23 or 31) that leaves 3 when divided by 4. The full answer rests on a theorem Albert Girard noticed in 1625, Fermat stated in a letter at Christmas 1640, and Euler first proved (published 1752–1755): an odd prime is a sum of two squares exactly when it leaves 1 when divided by 4 (5 = 1 + 4, 13 = 4 + 9, 17 = 1 + 16). So a number is the long side of a primitive triple exactly when all its prime factors are like that. The proof is harder than anything on this page.

Can two triangles share a long side? Yes: 65 = 5 × 13 is the long side of two primitive triangles and two copies (Question a finds them). Each new prime of the right kind doubles the number of primitive triangles.

Short sides one apart. 3, 4, 5 has short sides one apart. So does 20, 21, 29, the triangle on this topic’s card, and so does 119, 120, 169. Their p, q are 2, 1, then 5, 2, then 12, 5: can you see how each pair comes from the one before? (Question e asks for the next triangle.) These triangles are nearly half-squares, so their long side divided by a short side creeps toward √2 = 1.41421…: 5/3 = 1.667, 29/20 = 1.45, 169/119 = 1.4202. They never reach it, because no triple has two equal short sides: that would need c/a=2 c/a = \sqrt 2 to be a fraction, which it isn’t.

Where the rule breaks

Cubes. If squares split so easily into two squares, can a cube be split into two cubes, x3+y3=z3 x^3 + y^3 = z^3 ? No whole numbers work. Some come agonizingly close: 63+83=728 6^3 + 8^3 = 728 , one less than 93=729 9^3 = 729 , and 93+103=1,729 9^3 + 10^3 = 1{,}729 , one more than 123 12^3 . (1,729 is the taxi number Ramanujan told G. H. Hardy was “a very interesting number”: the smallest that is a sum of two cubes in two ways, 13+123 1^3 + 12^3 and 93+103 9^3 + 10^3 .) Around 1637 Pierre de Fermat wrote in the margin of his Arithmetica, next to Diophantus’ problem of splitting a square into two squares, that no cube, fourth power or any higher power splits into two of the same power, and that he had a proof the margin was too narrow to hold. It took until 1995 and Andrew Wiles to prove it. The story is in Can You Buy 100 Birds with 100 Coins?

The area is never a square. 3, 4, 5 has area 6; 5, 12, 13 has 30; 20, 21, 29 has 210. No Pythagorean triangle has an area that is a perfect square, and this one Fermat really did prove, by showing that any such triangle would lead to a smaller one, and that one to a smaller one still, for ever, which whole numbers can’t do. It is the only complete proof Fermat left, published in 1670 after his death, and it settles his margin note for fourth powers.

Who found the recipe?

Where this is used

Questions

Is 10, 24, 26 a primitive triple?

Pick an answer to see why.

a.★

Use the recipe with p = 7, q = 4, then with p = 8, q = 1. What do you notice? Then find two more right triangles with whole sides and the same long side.

Hint
Answer
b.★★

Find every right triangle with whole sides that has a short side of 15, and say which are primitive.

Hint
Answer
c.★★

Bhaskara’s Lilavati asks: “Hypotenuse being measured by eighty-five, say promptly, learned man, what uprights and sides will be rational?” Find every right triangle with whole sides and long side 85.

Hint
Answer

Which of these can be the long side of a primitive Pythagorean triangle?

Pick an answer to see why.

d.★★★

Prove that in every Pythagorean triple, at least one of the two short sides is a multiple of 3.

Hint
Answer
e.★★★

3, 4, 5; 20, 21, 29 and 119, 120, 169 have short sides one apart. Find the next such triangle, and check it.

Hint
Answer

Where to go next

Where these facts come from
  • Bhaskara’s Lilavati §§ 139–145 (the rules for rational right triangles from one side, from the hypotenuse, and from two assumed numbers; the example of the side 12 with 16, 20; 9, 15; 5, 13; 35, 37; the hypotenuse 85 with 68, 51 and 40, 75; Ganesa’s demonstration by the difference of squares; Colebrooke’s note that the second rule is Brahmagupta’s): H. T. Colebrooke, Algebra, with Arithmetic and Mensuration, from the Sanscrit of Brahmegupta and Bhascara (London, 1817; public domain), Internet Archive, read October 2026.
  • Euclid’s formula, the conditions for a primitive triple, the 16 primitive triples up to 100, the proof that every primitive triple comes from it, the properties (divisible by 3, 4 and 5, 60, the long side’s prime factors, the area never a square), the rational points of the circle, Proclus on the families of Pythagoras and Plato, the triples with short sides one apart: Wikipedia, “Pythagorean triple”, read October 2026.
  • Euclid’s Elements, Book X, Lemma 1 before Proposition 29, “To find two square numbers such that their sum is also square”: D. E. Joyce’s edition, Clark University, read October 2026.
  • Plimpton 322: about 1800 BC, Larsa, about 13 cm wide, fifteen rows, row 1 (119, 169) and row 4 (12,709, 18,541), Plimpton’s purchase about 1922 and Columbia University, the debate over its method and purpose: Wikipedia, “Plimpton 322”, read October 2026; the photo: Wikimedia Commons (public domain).
  • The Baudhayana Shulba Sutra 1.12–1.13 and its six rectangles, the dates of the Shulba Sutras: Wikipedia, “Shulba Sutras”, read October 2026.
  • Brahmagupta’s rule for rational right triangles in chapter 12 of the Brahmasphutasiddhanta (628): Wikipedia, “Brahmagupta”, read October 2026.
  • Diophantus’ Arithmetica II.8 and its example 16 = (16/5)² + (12/5)², Fermat’s note beside it around 1637, Wiles’s proof (1995): Wikipedia, “Fermat’s Last Theorem”, read October 2026.
  • Fermat’s right triangle theorem, published in 1670, his only complete proof, and its consequence for fourth powers: Wikipedia, “Fermat’s right triangle theorem”, read October 2026.
  • Primes as sums of two squares: Girard (1625), Fermat’s letter to Mersenne of 25 December 1640, Euler’s proof (letters of 1747 and 1749, published 1752–1755): Wikipedia, “Fermat’s theorem on sums of two squares”, read October 2026.
  • 1,729, Hardy’s taxi-cab story in his own words: Wikipedia, “Taxicab number”, read October 2026.
  • Laying out a square corner with 12, 9 and 15 feet: Journal of Light Construction, “Snapping Layout Lines for Walls”, 3 May 2017, read October 2026.
  • Pythagorean-hodograph curves, x′=u2−v2 x' = u^2 - v^2 , y′ = 2uv, σ=u2+v2 \sigma = u^2 + v^2 , and their use in real-time CNC interpolators (sampling every ~10⁻³ s): Rida T. Farouki, “Accuracy and efficiency improvements for CNC machines based on advanced toolpath descriptions and motion control algorithms” (slides, University of California, Davis), PDF, read October 2026.
  • Every triangle, count and answer on this page (the triangles with a side of 12, 7 and 15 and a long side of 65 and 85, the 19 in the hunt and the 7 primitive ones, the recipe table, that the recipe makes all 319 primitive triples with long side up to 2,000 and nothing else, the remainders of squares, 60 and the multiples of 3, 4 and 5, the long sides up to 100 and their prime factors, the triangles with short sides one apart and their ratios, the shared area 210, the cube near misses, Plimpton’s rows, Baudhayana’s rectangles, Bhaskara’s examples, the circle’s points) was computed in checks/textbooks/math-further-9-12/07/tmp/triples_numbers.py.