Audited 29 Jul 2026·Last updated 31 Jul 2026·4 citations·Tier 2·0 uses

Pythagorean Triples Calculator

Generate Pythagorean triples with Euclid's formula from m and n, or check whether three whole numbers form a triple and whether it is primitive.

Pythagorean Triples Calculator

What do you want to do?
Euclid's larger parameter. A whole number greater than n. It is not a side length — the sides are built from it as m² − n², 2mn and m² + n².
Euclid's smaller parameter, a whole number at least 1 and less than m. For a primitive triple, m and n must share no common factor and one must be odd while the other is even.
One of the two shorter sides, as a whole number. Ignored in generate mode.
The other short side, as a whole number. Order does not matter — the calculator sorts the two legs for display.
The longest side, as a whole number. It is tested as the hypotenuse specifically, so entering it smaller than a leg will correctly come back as 'not a triple'.
Triple
20, 21, 29
The three whole numbers, with the two legs sorted ascending and the hypotenuse last. Euclid's formula does not produce the legs in size order — m = 4, n = 1 gives 15 and 8 — so they are sorted here to match the conventional listing.
Leg a
20
Leg b
21
Hypotenuse c
29
Common factor
1
Perimeter
70
Area
210
Verdict
m = 5 and n = 2 generate the Pythagorean triple 20, 21, 29. Check: 20² + 21² = 400 + 441 = 841 = 29². It is PRIMITIVE — the three numbers share no common factor, because m and n are coprime and of opposite parity.

Background.

The Quanta Pythagorean triples calculator does two things. In generate mode it builds a triple from Euclid's two parameters m and n, using a = m² − n², b = 2mn and c = m² + n² — the construction that produces every primitive triple there is. In check mode it takes three whole numbers you already have and tells you whether they satisfy a² + b² = c², whether the triple is primitive, and if it is not, which smaller triple it is a scaled copy of. With the default m = 5 and n = 2, the calculator returns 20, 21, 29 — a primitive triple with a perimeter of 70 and an area of 210.

A Pythagorean triple is three positive whole numbers that fit the Pythagorean theorem exactly. Most right triangles do not have integer sides: pick two legs at random and the hypotenuse is almost always irrational. Triples are the rare cases where all three come out whole, which is exactly why carpenters, masons and surveyors have used them to lay out square corners for four thousand years. Measure 3 along one line and 4 along the other, and if the diagonal is exactly 5 the corner is square — no protractor required.

A triple is called primitive when its three numbers share no common factor. 3, 4, 5 is primitive; 6, 8, 10 and 30, 40, 50 are not, because they are just 3, 4, 5 doubled and multiplied by ten. Every non-primitive triple is an integer multiple of a primitive one, so the primitives are the whole story and the rest are copies. That is the reason this page reports a common factor as its own output: it turns 'is it primitive' into a number you can read rather than a judgement you have to make.

Euclid's formula is complete, which is a stronger claim than it first sounds. Every primitive triple comes from exactly one pair (m, n) with m > n > 0, m and n sharing no common factor, and one of them odd while the other is even. Relax any of those conditions and you still get a genuine triple — it just will not be primitive. Take m = 3 and n = 1, both odd: the formula returns 6, 8, 10, which is 2 × (3, 4, 5). This calculator reports that honestly rather than refusing the input, and it reaches the answer by computing the greatest common divisor of the three results rather than by checking the parity of m and n, so the two facts confirm each other instead of one assuming the other.

One scope limit belongs beside the answer. Triples are about whole numbers, so both modes reject anything with a fractional part rather than rounding it. If you have three measured lengths and want to know whether they make a right triangle, that is a different question and the Pythagorean theorem calculator or the triangle inequality page will answer it. And two of the most-used right triangles in geometry — the 30-60-90 and the 45-45-90 — can never be triples at all, because their side ratios involve √3 and √2 and no whole numbers can hit an irrational ratio exactly.

Below the calculator you will find the identity that proves Euclid's formula always works, the two conditions that make its output primitive, the list of the sixteen primitive triples with hypotenuse under 100 against which this page's generator was checked, and the primary sources: MathWorld, Euclid's Elements Book X, and Keith Conrad's expository notes from the University of Connecticut.

What is pythagorean triples calculator?

A Pythagorean triple is a set of three positive integers (a, b, c) satisfying a² + b² = c², so that a right triangle can be built with all three sides whole numbers. The smallest and most famous is 3, 4, 5, since 9 + 16 = 25. Others include 5, 12, 13 and 8, 15, 17 and 7, 24, 25 and 20, 21, 29. A triple is primitive when a, b and c have no common factor; equivalently, as Keith Conrad's Lemma 1.1 shows, when they are pairwise relatively prime, or when merely two of the three are relatively prime — the three statements turn out to be the same condition. Euclid's formula generates them all: for integers m > n > 0, the triple a = m² − n², b = 2mn, c = m² + n² always satisfies the theorem, because (m² − n²)² + (2mn)² expands to m⁴ + 2m²n² + n⁴, which is (m² + n²)². MathWorld gives this as its Equation (11) in the notation (v² − u², 2uv, u² + v²), and states the conditions under which the output is primitive: the two parameters must be relatively prime and of opposite parity. Conrad's Theorem 1.2 states the same result with the parameters called k and ℓ, and adds the converse — every primitive triple arises this way. Euclid himself gives the construction in Elements Book X, as the first lemma before Proposition 29: 'To find two square numbers such that their sum is also square.' The oldest surviving evidence that anyone was systematically listing triples is far older still: the Babylonian clay tablet Plimpton 322, dated to around 1800 BCE, records fifteen of them, roughly twelve centuries before Pythagoras.

How to use this calculator.

  1. Pick the mode. Generate builds a triple from Euclid's parameters. Check tests three numbers you already have.
  2. In generate mode, enter m and n as whole numbers with m greater than n and n at least 1. They are not side lengths — the sides are computed from them. For a primitive result, choose m and n sharing no common factor, with one odd and the other even.
  3. Read the triple at the top, then the three individual numbers underneath, along with the perimeter and area of the right triangle they describe.
  4. Read the common factor. A value of 1 means the triple is primitive. Anything larger means the triple is that many times a smaller one, and the verdict names the smaller one.
  5. In check mode, enter the two legs and the hypotenuse as whole numbers. Leg order does not matter — the calculator sorts them — but the hypotenuse field is tested as the hypotenuse, so putting the largest number anywhere else will correctly return 'not a triple'.
  6. Read the verdict for the arithmetic written out in full: the two squares, their sum, and the square of the hypotenuse. When the answer is no, both sides of the failed equation are shown so you can see how far off you were.
  7. To sweep for triples, keep n fixed and step m upward, or vice versa. Every coprime, opposite-parity pair gives a new primitive triple, and no pair ever repeats one.

The formula.

a = m² − n² , b = 2mn , c = m² + n² (m > n > 0)

WHY EUCLID'S FORMULA ALWAYS WORKS. Expand the two legs squared and add them. (m² − n²)² = m⁴ − 2m²n² + n⁴, and (2mn)² = 4m²n². Adding gives m⁴ + 2m²n² + n⁴, which factors as (m² + n²)². So a² + b² = c² holds identically for every pair of integers m and n, with no conditions at all — the conditions are needed only for primitivity, not for the triple itself.

WORKING THE DEFAULT ALL THE WAY THROUGH. With m = 5 and n = 2: a = 25 − 4 = 21, b = 2 × 5 × 2 = 20, and c = 25 + 4 = 29. The formula happened to put the larger leg first here, so the calculator sorts them and reports 20, 21, 29. Verifying: 20² + 21² = 400 + 441 = 841, and 29² = 841. The greatest common divisor of 20, 21 and 29 is 1, so the triple is primitive — consistent with the rule, since 5 and 2 share no factor and 5 is odd while 2 is even. The perimeter is 20 + 21 + 29 = 70 and the area is 20 × 21 ÷ 2 = 210.

WHAT MAKES A TRIPLE PRIMITIVE. Two conditions on the parameters, and both are needed. If m and n share a factor d, then every term of the triple is divisible by d², so the result is a scaled copy. If m and n have the same parity — both odd or both even — then m² − n² and m² + n² are both even and the whole triple is even. Take m = 3 and n = 1, both odd: the formula gives 8, 6, 10, which sorts to 6, 8, 10 and is exactly twice 3, 4, 5. This calculator does not check the parity rule to decide primitivity. It computes the greatest common divisor of the three output numbers directly, which is a stronger statement, works identically in check mode where no parameters exist, and lets the parity rule be a prediction the page can be tested against rather than an assumption baked into it.

COMPLETENESS. Every primitive triple comes from exactly one valid (m, n) pair, and every other triple is a whole-number multiple of a primitive one. So the generator plus multiplication reaches every Pythagorean triple that exists — 'generate' really is a complete answer rather than a sampler. As a check on this page's implementation, enumerating every coprime opposite-parity pair with m up to 10 reproduces exactly the sixteen primitive triples with hypotenuse below 100 that MathWorld publishes: 3-4-5, 5-12-13, 8-15-17, 7-24-25, 20-21-29, 12-35-37, 9-40-41, 28-45-53, 11-60-61, 33-56-65, 16-63-65, 48-55-73, 36-77-85, 13-84-85, 39-80-89 and 65-72-97. That enumeration is a test in the suite, not a claim in prose.

EXACTNESS AND RANGES. Every value here is a whole number, and every comparison — including the crucial a² + b² = c² — is an exact decimal comparison at 40 significant digits rather than a floating-point one, so a triple can never be missed or invented by a rounding error in the last bit. The input caps exist for the same reason: m is limited to 5000 so the hypotenuse stays under 25 million and the area under about 6.3 × 10¹⁴, comfortably inside the range where JavaScript numbers are exact integers.

A worked example.

Example

Someone wants a Pythagorean triple that is not one of the two or three everybody already knows — something to lay out a large square corner where 3-4-5 would be too small to be accurate. Leaving the mode on Generate and entering m = 5, n = 2 returns the triple 20, 21, 29, with a common factor of 1, a perimeter of 70 and an area of 210. Step by step: a = m² − n² = 25 − 4 = 21, b = 2mn = 2 × 5 × 2 = 20, and c = m² + n² = 25 + 4 = 29. The formula produced the legs in the order 21 then 20, so the calculator sorts them and shows 20, 21, 29. Verifying by hand: 20² = 400, 21² = 441, and 400 + 441 = 841, which is 29 × 29 exactly. The common factor of 1 confirms the triple is primitive — and it should be, because 5 and 2 share no common divisor and one is odd while the other is even, which are precisely the two conditions Euclid's formula needs. Practically, 20, 21, 29 is a useful triple because its two legs are almost the same length: it lays out a right angle from a nearly square rectangle, which is easier to set on a site than the long thin 3-4-5. Now change n from 2 to 1, so both parameters are odd. The formula gives a = 25 − 1 = 24, b = 2 × 5 × 1 = 10 and c = 25 + 1 = 26, so the triple becomes 10, 24, 26, the common factor becomes 2, and the verdict says so explicitly: not primitive, and equal to 2 × the primitive triple 5, 12, 13. Nothing has gone wrong — 10, 24, 26 satisfies the theorem perfectly well, since 100 + 576 = 676 = 26² — but it is a copy rather than a new triple, which is exactly what the same-parity condition predicts. Switching to Check mode and entering 20, 21 and 29 returns the same numbers with the verdict 'Yes — 20, 21, 29 is a Pythagorean triple', while entering 20, 21 and 28 returns a flat no, showing 400 + 441 = 841 against 28² = 784.

hypotenuse29
modegenerate
leg A20
leg B21
m5
n2

Frequently asked questions.

What is a Pythagorean triple?
Three positive whole numbers a, b and c with a² + b² = c², so a right triangle can be drawn with all three sides whole. The smallest is 3, 4, 5 because 9 + 16 = 25. Most right triangles are not triples — pick any two legs at random and the hypotenuse is almost certainly irrational — which is exactly why the whole-number cases are worth cataloguing. They are what let a builder check a square corner with a tape measure and nothing else: 3 along one wall, 4 along the other, and if the diagonal reads exactly 5 the corner is true.
What makes a triple primitive?
Its three numbers share no common factor. 3, 4, 5 is primitive; 6, 8, 10 is not, because every term is divisible by 2 and it is just 3, 4, 5 doubled. Keith Conrad's Lemma 1.1 shows three equivalent ways to say this: the three numbers have no common factor, they are pairwise relatively prime, or merely two of the three are relatively prime. Every non-primitive triple is an integer multiple of exactly one primitive triple, so the primitives are the complete list and everything else is a scaled copy. This calculator reports the greatest common divisor as its own output, so primitivity is a number you read rather than something you have to work out.
How does Euclid's formula generate triples?
Pick two whole numbers m > n > 0 and set a = m² − n², b = 2mn and c = m² + n². The identity (m² − n²)² + (2mn)² = (m² + n²)² holds for every pair, so the result is always a triple. For the output to be primitive you need two extra conditions: m and n must share no common factor, and one must be odd while the other is even. MathWorld states this as its Equation (11) with parameters u and v; Conrad's Theorem 1.2 states it with k and ℓ and adds the converse, that every primitive triple arises from exactly one such pair. Relax the conditions and you still get a genuine triple, just not a primitive one — m = 3, n = 1 gives 6, 8, 10.
How is this different from the Pythagorean theorem calculator?
Different domain. Quanta's Pythagorean theorem calculator solves one right triangle over the real numbers: give it any two sides, in any units, and it returns the third, together with area and perimeter. It neither knows nor cares whether the answers are whole numbers, and it cannot generate anything — you have to bring it a triangle. This page is number theory. Its generate mode takes two parameters that are not side lengths at all and constructs sides from them, and its check mode asks whether three specific integers are a triple and whether that triple is primitive, which are questions a real-valued solver cannot express. Use that page for measurements; use this one for whole numbers.
Are there infinitely many Pythagorean triples?
Yes, and infinitely many primitive ones. Every choice of m > n > 0 gives a triple, and there are infinitely many such pairs; every coprime opposite-parity pair gives a primitive one, and there are infinitely many of those too. A quick way to see it: take n = 1 and let m run through the even numbers 2, 4, 6, 8 and so on. Each gives a primitive triple — 3-4-5, 15-8-17, 35-12-37, 63-16-65 — and no two are the same, because the hypotenuse m² + 1 strictly increases. Multiplying any triple by a whole number gives another triple, so each primitive spawns an infinite family of its own.
Can a 30-60-90 or 45-45-90 triangle be a Pythagorean triple?
Never. A 45-45-90 triangle has sides in the ratio 1 : 1 : √2, and a 30-60-90 triangle has sides in the ratio 1 : √3 : 2. Both √2 and √3 are irrational, so no choice of whole numbers can hit those ratios exactly — if the legs of a 45-45-90 triangle are whole numbers, the hypotenuse is that number times √2 and cannot be. Pythagorean triples therefore describe right triangles whose angles are never the tidy 30, 45 or 60 degrees: the 3-4-5 triangle has angles of roughly 36.87° and 53.13°. The two families are complementary — one has whole-number sides and awkward angles, the other has tidy angles and irrational sides.
Who discovered Pythagorean triples?
They predate Pythagoras by well over a thousand years. The Babylonian clay tablet Plimpton 322, dated to around 1800 BCE and now at Columbia University, lists fifteen of them in a systematic, sorted arrangement that no one could produce by accident. Eleanor Robson's 2001 reassessment in Historia Mathematica argues the tablet was a teacher's list of parameters for setting problems rather than an astronomical or trigonometric table, but either way the mathematics is unambiguous. Ancient Indian and Chinese sources record the 3-4-5 relationship independently. What the Greek tradition contributed was the general construction and the proof that it produces every primitive triple, which is what Euclid records in Book X of the Elements.

References& sources.

  1. [1]Wolfram Research, MathWorld — 'Pythagorean Triple' (live revision retrieved 2026-07-29). Equation (11) gives the parametrisation (v² − u², 2uv, u² + v²) with the primitivity conditions that u and v be relatively prime, of opposite parity, and v > u. The entry also publishes the sixteen primitive triples with hypotenuse below 100, against which this page's generator was enumerated in its test suite. Open access.
  2. [2]Conrad, Keith. 'Pythagorean Triples.' Expository notes, Department of Mathematics, University of Connecticut. Theorem 1.2 and Equation (1.1): a = k² − ℓ², b = 2kℓ, c = k² + ℓ² for k > ℓ > 0 with (k, ℓ) = 1 and k ≢ ℓ mod 2, together with the converse. Table 1 and the following counter-example (k = 3, ℓ = 1 gives the non-primitive 8, 6, 10) were used as the independent cross-check on this page's output. PDF retrieved and read 2026-07-29; open access.
  3. [3]Euclid, Elements, Book X, Lemma 1 preceding Proposition 29 — 'To find two square numbers such that their sum is also square', the classical construction behind the m and n parametrisation. David E. Joyce web edition of the Heath translation, Clark University; statement confirmed verbatim on retrieval 2026-07-29. Open access.
  4. [4]Robson, Eleanor. 'Neither Sherlock Holmes nor Babylon: A Reassessment of Plimpton 322.' Historia Mathematica 28 (2001): 167–206, DOI 10.1006/hmat.2001.2317. The definitive modern analysis of the Babylonian tablet listing fifteen Pythagorean triples around 1800 BCE. Cited for the historical claim only, not for any computed value. Publisher-gated; DOI record and abstract open.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 977 calculators remain free
  • No billing is enabled
Coming soon