The Euclidean algorithm and Bézout's identity
Statement
Let \( a, b \in \mathbb{Z} \) with not both \( a \) and \( b \) equal to \( 0 \). Let \( d = \gcd(a,b) \) denote the greatest common divisor of \( a \) and \( b \), i.e. the unique positive integer such that (i) \( d \mid a \) and \( d \mid b \), and (ii) for every \( c \in \mathbb{Z} \) with \( c \mid a \) and \( c \mid b \), we have \( c \mid d \). Then there exist integers \( x, y \in \mathbb{Z} \) (not in general unique) such that \[ ax + by = d. \] Moreover \( d \) is the smallest positive integer expressible in the form \( ax+by \) with \( x,y \in \mathbb{Z} \), and the set of all such integer combinations \( \{ax+by : x,y \in \mathbb{Z}\} \) is exactly the set of integer multiples of \( d \). The pair \( (x,y) \) — and, along the way, the value \( d \) itself — can be computed explicitly and in finitely many steps by the Euclidean algorithm.
Why it matters
Bézout's identity converts a purely divisibility-theoretic object, the gcd, into a linear algebraic one: an explicit \( \mathbb{Z} \)-linear combination. This single fact is the hinge on which most of elementary number theory turns. It is the reason Euclid's lemma holds (if \( p \) is prime and \( p \mid ab \) then \( p \mid a \) or \( p \mid b \)), which in turn is the engine behind the Fundamental Theorem of Arithmetic; it is what makes modular inverses computable (solving \( ax \equiv 1 \pmod n \) is exactly finding \( x \) with \( ax + ny = 1 \)), which underlies the Chinese Remainder Theorem and RSA-style cryptography; and it is the prototype for the far-reaching structural fact that \( \mathbb{Z} \) is a principal ideal domain.
Algorithmically, the theorem is not merely an existence statement: the Euclidean algorithm and its extended form give a genuinely efficient (polynomial-time, in fact logarithmic in the number of steps) method for producing \( d \), \( x \), and \( y \) simultaneously, which is why it is a working tool and not just a piece of pure existence theory.
Hypotheses
Proof
Result
Reading. The greatest common divisor of two integers, not both zero, is always achievable as a "signed integer combination" of the two — and the Euclidean algorithm's chain of divisions, read backwards, hands you such an \( x \) and \( y \) explicitly.
Scope. Valid for all \( a,b\in\mathbb{Z} \) not both \( 0 \); the coefficients \( x,y \) are never unique (replacing \( (x,y) \) by \( (x+k b/d,\ y-ka/d) \) for any \( k\in\mathbb{Z} \) gives another valid pair); the statement and proof generalise verbatim to any Euclidean domain (e.g. \( F[t] \) for a field \( F \), or the Gaussian integers \( \mathbb{Z}[i] \)) once "division algorithm" and "smaller" are reinterpreted via the relevant Euclidean norm.
Corollaries & converses
- Euclid's Lemma. If \( p \) is prime and \( p \mid ab \), then \( p\mid a \) or \( p \mid b \). (If \( p \nmid a \) then \( \gcd(p,a)=1 \), so \( 1 = px+ay \) for some \( x,y \); multiply by \( b \) to get \( b = pbx + aby \), and \( p \) divides both terms on the right since \( p\mid ab \).)
- Existence of modular inverses. \( a \) has a multiplicative inverse mod \( n \) iff \( \gcd(a,n)=1 \), and the extended algorithm computes it directly: \( ax+ny=1 \Rightarrow ax\equiv 1 \pmod n \).
- \( \mathbb{Z} \) is a Bézout domain / PID. Every ideal \( (a,b) \) of \( \mathbb{Z} \) equals \( (d) \) with \( d=\gcd(a,b) \), by Step 10; iterating shows every finitely generated ideal of \( \mathbb{Z} \) is principal.
- Converse fails as a "detection" tool. The existence of some \( x,y \) with \( ax+by=1 \) does prove \( \gcd(a,b)=1 \) (by Step 10's minimality argument any positive value in \( S \) is a multiple of \( d \), so \( d\mid 1 \Rightarrow d=1 \)) — so in this coprimality case the converse genuinely holds and is used constantly. But it is false that every representation \( ax+by=d \) is unique, and it is false that an arbitrary pair \( (x,y) \) with \( ax+by = k \) for some multiple \( k \) of \( d \) tells you \( \gcd(a,b)=k \) — e.g. \( 4\cdot 3 + 6\cdot(-2) = 0 \) says nothing about \( \gcd(4,6) \) beyond \( \gcd(4,6)\mid 0 \), which is vacuous.
Fails without
- Drop "not both zero": \( a=b=0 \). Every integer is a common divisor, there is no greatest one, and \( S = \{0\cdot x+0\cdot y\} = \{0\} \) has no positive element, so the minimality argument of Step 10 has nothing to minimise over — the theorem's statement is not merely false here, it is not even meaningful.
- Replace \( \mathbb{Z} \) by a ring without a division algorithm: in \( \mathbb{Z}[\sqrt{-5}] \), take \( \alpha = 2,\ \beta = 1+\sqrt{-5} \). One can show \( 1 \) is a common divisor bound in the sense that no non-unit divides both up to the obvious factors, yet the ideal \( (2,\,1+\sqrt{-5}) \) is not principal — there is no single element \( \delta \) with \( (\delta) = (2,1+\sqrt{-5}) \), so there is no candidate "\( d \)" for which one could even ask whether \( d = 2x+(1+\sqrt{-5})y \). The proof breaks at the very first step (Step 2), since \( \mathbb{Z}[\sqrt{-5}] \) admits no division algorithm relative to any norm making it Euclidean.
- Drop finiteness of the descent (hypothetical): if one tried to run the same idea in a ring where remainders needn't strictly decrease in a well-ordered value (e.g. formally in \( \mathbb{Q} \) itself, where "remainder" \( 0 \le r \lt n \) can be forced to \( 0 \) trivially but the notion of "common divisor" collapses since every non-zero rational divides every other), termination (Step 4) and the divisor structure both dissolve — gcd is not a meaningful invariant in a field.
Common errors
- Running the forward Euclidean algorithm to find \( d \), then guessing \( x,y \) by trial and error instead of systematically back-substituting (Step 8) — this misses the algorithmic content of the theorem and is error-prone for anything beyond tiny examples.
- Believing \( x,y \) are unique. They are not; students are often thrown when a textbook and a calculator give "different" correct answers to the same Bézout problem.
- Sign errors in back-substitution: forgetting that \( r_{i+1} = r_{i-1} - q_ir_i \) needs to be tracked with the correct sign at each stage, especially when \( a \) or \( b \) is negative and Step 1's reduction hasn't been undone at the end.
- Concluding \( \gcd(a,b) = k \) merely because some \( x,y \) were found with \( ax+by=k \); as the Corollaries section notes, this only pins down \( \gcd(a,b) \) as a divisor of \( k \), not as equal to it, unless \( k=1 \) (or minimality is separately verified).
- Confusing "\( \gcd(a,b) \) is an integer combination of \( a,b \)" with "every integer combination of \( a,b \) is a multiple of the gcd achieved with small coefficients" — the coefficients \( x,y \) produced by naive search can be far larger than those from the extended algorithm, though both are valid.
Discussion
The Euclidean algorithm is arguably the oldest non-trivial algorithm in continuous use, appearing in Euclid's Elements (Book VII, Propositions 1–2) as a test for commensurability of magnitudes, phrased geometrically rather than arithmetically. Bézout's name attaches to the identity via Étienne Bézout's 18th-century work on resultants of polynomials, though the integer case was known earlier (implicitly to Bachet, and in essence to the algorithm itself) — a reminder that theorem names in number theory often reflect a later, sharper articulation rather than strict priority.
Structurally, the theorem is the concrete, computational face of the abstract fact that \( \mathbb{Z} \) is a principal ideal domain: the set \( \{ax+by\} \) is precisely the ideal \( (a,b) \), and Bézout's identity says this ideal is principal, generated by \( \gcd(a,b) \). Anywhere this ideal-theoretic property holds — Euclidean domains generally, including \( F[t] \) and \( \mathbb{Z}[i] \) — an analogous identity and an analogous algorithm exist, obtained by replacing "size" \( |r| \) with the ring's Euclidean norm.
It is worth being precise about logical dependencies: the existence of \( x,y \) can be proved two genuinely different ways — constructively via the terminating algorithm and back-substitution (Steps 2–9), or non-constructively via well-ordering applied to the set of positive combinations (Step 10). The constructive route is what makes the theorem useful (it hands you an algorithm, not just a proof of existence), while the non-constructive route is what most cleanly explains why the theorem is true at the level of ideal theory. Good exposition keeps both, because they answer different questions: "how do I compute \( x,y \)?" versus "why must such \( x,y \) exist at all?"
Common misconception: that Bézout's identity gives a way to compute \( \gcd(a,b) \) — it does not; the gcd must already be known (or computed via the forward pass of the algorithm) before the identity can be exhibited. The identity certifies a value as the gcd once you already believe it is one (e.g. once you have found \( x,y \) with \( ax+by = g \) and separately checked \( g \mid a, g\mid b \)), but blind search for such \( x, y, g \) without the algorithm's structure is not a gcd-finding method.
Worked examples
Reading. \( x=-2,\ y=5 \) is one valid Bézout pair; check: \( -504+525=21 \). Correct.
Reading. Check: \( 17\times 6 = 102 = 101+1 \equiv 1 \pmod{101}\). This is exactly how modular inverses are computed in practice, e.g. in RSA key generation.
Problems
- Compute \( \gcd(840, 252) \) using the Euclidean algorithm, and hence find integers \( x,y \) with \( 840x+252y=\gcd(840,252) \).
Solution
\( 840 = 3\cdot 252 + 84 \); \( 252 = 3\cdot 84 + 0 \). So \( \gcd = 84 \). Back-substitute: \( 84 = 840 - 3\cdot 252 \), so \( x=1, y=-3 \) works directly (only one division was needed). Check: \( 840 - 756 = 84 \). Correct. - Show that if \( \gcd(a,b)=1 \) and \( \gcd(a,c)=1 \), then \( \gcd(a,bc)=1 \).
Solution
By the theorem, choose \( x_1,y_1 \) with \( ax_1+by_1=1 \) and \( x_2,y_2 \) with \( ax_2+cy_2=1 \). Multiply: \( (ax_1+by_1)(ax_2+cy_2)=1 \). Expand: \( a(ax_1x_2+cx_1y_2+bx_2y_1) + bc(y_1y_2) = 1 \). This exhibits \( 1 \) as \( a X + bc\, Y \) with \( X = ax_1x_2+cx_1y_2+bx_2y_1,\ Y=y_1y_2 \), both integers. By the minimality/converse argument (Corollaries), \( \gcd(a,bc) \mid 1 \), so \( \gcd(a,bc)=1 \). - Find all integer solutions \( (x,y) \) to \( 6x+9y=15 \), or show none exist.
Solution
\( \gcd(6,9)=3 \), and \( 3\mid 15 \), so by Step 10 (the combination set is exactly \( 3\mathbb{Z} \), and \( 15\in 3\mathbb{Z} \)) solutions exist. A base solution: \( 6\cdot(-1)+9\cdot 1 = 3 \), scale by \( 5 \): \( 6\cdot(-5)+9\cdot 5=15 \), i.e. \( x_0=-5,y_0=5 \). General solution: \( x=-5+3k,\ y=5-2k \) for \( k\in\mathbb{Z} \) (step sizes \( b/d=3 \), \( a/d=2 \) from Result's uniqueness remark). - Prove that if \( d=\gcd(a,b) \) and \( ax+by=d \), then \( \gcd(x,y) \) need not be \( 1 \) — but show that if additionally \( a=da',\,b=db' \) with \( \gcd(a',b')=1 \) (always possible), the pair \( (x,y) \) can be chosen with \( \gcd(x,y)=1 \). Illustrate with \( a=6,b=4 \).
Solution
\( d=2,\ a'=3,b'=2,\ \gcd(3,2)=1 \), and indeed a Bézout pair for \( 3,2 \) is \( 3(1)+2(-1)=1 \), scaling gives \( 6(1)+4(-1)=2=\gcd(6,4) \), with \( \gcd(x,y)=\gcd(1,-1)=1 \). In general dividing through by \( d \) reduces to the coprime case \( a'x+b'y=1 \), whose Bézout coefficients \( x,y \) automatically satisfy \( \gcd(x,y)=1 \) (any common divisor of \( x,y \) would divide \( a'x+b'y=1 \)). Not every valid pair for the original \( a,b \) has \( \gcd(x,y)=1 \) (e.g. adding a multiple of \( (b/d,-a/d) \) can introduce a common factor into \( x,y \)), but at least one choice always does. - Let \( a,b,n \) be positive integers with \( \gcd(a,n)=1 \). Using Bézout's identity, prove that the map \( t \mapsto at \bmod n \) is a bijection from \( \{0,1,\ldots,n-1\} \) to itself.
Solution
Since \( \gcd(a,n)=1 \), by the theorem there exist \( x,y \) with \( ax+ny=1 \), so \( ax\equiv 1\pmod n \); call \( x \) the inverse \( a^{-1} \bmod n \). The map \( s\mapsto a^{-1}s \bmod n \) is then a two-sided inverse of \( t\mapsto at\bmod n \) on \( \mathbb{Z}/n\mathbb{Z} \): \( a^{-1}(at) \equiv (a^{-1}a)t \equiv t \pmod n \), and symmetrically \( a(a^{-1}s)\equiv s\pmod n \). A map with a two-sided inverse on a finite set is a bijection.