StatGardenREF. DESK
Calculators/Maths/Pythagorean triple generator
Maths

Pythagorean triple generator

Builds a right-triangle integer triple from two generator numbers (Euclid’s formula).

Published 6 August 2026 · Updated 23 September 2026

What this calculator does

Euclid gave a formula that generates every Pythagorean triple from two whole numbers. Taking m = 2 and n = 1 produces 3, 4, 5, the triple everyone knows, and larger generators produce the rest.

Whether the result is primitive depends on the generators. They must share no common factor and must have opposite parity, which is why m = 3 with n = 1 gives 8, 6, 10 rather than a new primitive triple.

The formula

Formulaa = m²−n², b = 2mn, c = m²+n² for m > n > 0; primitive when gcd(m,n)=1 and m, n have opposite parity

One leg is m squared less n squared, the other is twice m times n, and the hypotenuse is m squared plus n squared. The identity holds for any m greater than n.

TermMeaning
Pythagorean tripleThree whole numbers where the squares of two sum to the square of the third.
Primitive tripleOne where the three numbers share no common factor.
Euclid's formulaThe generator that produces every triple from two parameters.

The inputs explained

FieldWhat to enter
m (larger generator)The larger generator. Must exceed n.
n (smaller generator)The smaller generator, at least 1. Opposite parity to m gives a primitive triple.

When to use it

Finding right triangles with whole sides

Useful for constructing exact problems and for building square corners.

Understanding primitivity

Seeing which generators give primitive triples makes the condition concrete.

Generating test data

Whole-number triangles avoid rounding in worked examples.

Worked examples

Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.

Which generators give primitive triples?

Four values of m against the same n.

n held at 1
Generator mTriple (a, b, c)Primitive triple?
m = 23, 4, 5Yes
m = 38, 6, 10No: gcd(m,n)=1, m and n share parity
m = 415, 8, 17Yes
m = 524, 10, 26No: gcd(m,n)=1, m and n share parity
m = 2 gives the familiar 3, 4, 5 and m = 4 gives 15, 8, 17, both primitive. m = 3 and m = 5 are odd like n, so they share parity and produce 8, 6, 10 and 24, 10, 26, which are just doubled versions of smaller triples.

Questions

Does the formula generate every triple?

Every primitive triple, yes, and every non-primitive one is a whole-number multiple of a primitive. So between the formula and scaling, the two together produce all of them.

Why does parity matter?

Because if m and n are both odd, all three results come out even, so the triple has a common factor of 2 and is not primitive. Opposite parity is needed to avoid that.

Why is 3, 4, 5 so well known?

Because it is the smallest triple and therefore the most practical. Builders have used a 3-4-5 measurement to construct square corners for thousands of years, long before the theorem was formally proved.

Are there triples with no common small factor patterns?

Every primitive triple has one even leg and one odd leg, and the hypotenuse is always odd. Those constraints follow directly from the formula and hold without exception.

For distance in three dimensions, see the 3D distance calculator. For triangle measurement, see the triangle area calculator.