Linear Congruences
When can we solve ? How many answers are there? This simple question — solving a linear equation modulo an integer — turns out to encode the entire arithmetic structure of . Over the rational numbers, solving is straightforward. A nonzero always yields the unique solution . Working modulo is different. It introduces genuinely new phenomena. An equation may have no solutions at all. It may have exactly one solution. Or it may have many solutions. The outcome depends on how interacts with . The idea matters because linear congruences are the atomic building block of modular arithmetic. Every question about solving polynomial congruences reduces to this equation. So does finding modular inverses. So does combining several congruences with different moduli, as in the Chinese Remainder Theorem. All of these reduce, at some stage, to understanding exactly this equation. Cryptographic algorithms such as RSA rest on this understanding. So do error-correcting codes and the extended Euclidean algorithm. All require a precise grasp of when is solvable. They also require knowing what its solution set looks like. The big picture is that solvability and solution-counting are governed entirely by the greatest common divisor . This single invariant determines everything. It determines whether a solution exists. If so, it determines exactly how many incongruent solutions there are modulo . The mechanism behind this is Bezout's Identity. It converts the divisibility condition into an explicit algorithm. That algorithm is the extended Euclidean algorithm, used for producing solutions. This article gives the complete solvability criterion for . It describes the full solution set when solutions exist. It proves both directions rigorously. We work through two asymmetric numerical examples. We examine a counterexample showing why the gcd condition cannot be dropped. We close by connecting linear congruences to the machinery of simultaneous congruences. This machinery culminates in the Chinese Remainder Theorem.
- The congruence is solvable in if and only if .
- When solvable, the solutions form exactly distinct residue classes modulo .
- These solutions are evenly spaced: consecutive solutions differ by .
- When , there is a unique solution modulo , given by .
- The extended Euclidean algorithm both certifies solvability and constructs an explicit solution.
- Key idea: solving is really solving the linear Diophantine equation , so gcd divisibility is the whole story.
Where this lives today
Linear congruences are the computational engine behind the extended Euclidean algorithm's most common application: computing modular inverses, which underlies the RSA cryptosystem's key generation and decryption steps. In coding theory, solving linear congruences over appears in constructing check digits (such as ISBN and UPC codes) and in decoding certain linear codes. In computer science, hashing schemes and pseudorandom number generators (linear congruential generators) are literally defined by iterating , and understanding their period and coverage properties requires exactly the solvability theory developed here. In pure mathematics, the step from a single linear congruence to systems of congruences with different, possibly non-coprime moduli is precisely the subject of the Chinese Remainder Theorem, which decomposes into a product of simpler rings and reduces simultaneous solvability to compatibility conditions built from exactly the gcd criterion proved above.
Ask the tutor: How does the solvability criterion here extend to solving systems of linear congruences with different moduli, as in the Chinese Remainder Theorem?
Let be integers with . A linear congruence is an equation of the form
where ranges over the integers. An integer is a solution if . Two solutions are considered the same solution if , since replacing a solution by any integer congruent to it modulo yields another solution (this is immediate from the definition of congruence: if then ). Accordingly, we count solutions as residue classes modulo , i.e. elements of , rather than as individual integers. The congruence is called solvable if at least one such residue class exists.
Intuition
Think of as equally spaced points arranged around a circle, labeled . Multiplication by is a map from this circle to itself: it sends each point to the point . Solving asks: which points get sent to by this map? If , multiplication by is a bijection of the circle onto itself (it merely permutes the points), so every target is hit exactly once — a unique solution. If , the map is no longer a bijection: it is -to-one onto its image, and its image consists only of the multiples of modulo . So is hit only if , and when it is hit, it is hit exactly times — giving solutions, evenly spaced apart around the circle. This "evenly spaced" structure is not a coincidence; it comes from rewriting the congruence as a genuine linear equation over the integers and invoking Bezout's identity, which certifies that is exactly the set of integer combinations of and .
Let be integers with , and let . Then: 1. The congruence has a solution if and only if . 2. If , then the congruence has exactly incongruent solutions modulo . If is any one solution, the complete list of incongruent solutions is
3. In particular, if , the congruence has a unique solution modulo , namely
where is a modular inverse of modulo .
We prove each part in turn. Throughout, .
Part 1: solvability . () Suppose is a solution, so . Then there is an integer with
Since and , we get . This proves the forward direction. () Suppose . By Bezout's Identity, since , there exist integers such that
Write for some integer (using ). Multiplying the Bezout identity by gives
so setting we get , i.e. . Hence is a solution. This proves solvability, completing Part 1.
Part 2: the solution set, given solvability. Assume now , and let be a solution obtained as above (or any solution — the argument below applies to any single fixed solution). Step A (every listed value is a solution). We claim that for every integer ,
is again a solution. Indeed,
Since is a solution, ; and the second term is manifestly a multiple of because is an integer (as ). Hence the whole right-hand side is a multiple of , so is a solution for every integer . Step B (every solution has this form). Conversely, let be any solution. Then both and , so subtracting,
Write , with (this is possible and is a standard property of dividing through by the gcd: if a common factor divided both and , then would divide both and and exceed , a contradiction). The divisibility becomes
(cancelling the common factor , valid since ). Since , Euclid's lemma (a direct consequence of Bezout's identity: if and , write , multiply by to get , and note divides both terms on the left) gives
Thus for some integer , i.e. . This proves every solution is congruent to one of the form in Step A. Step C (exactly incongruent classes). By Steps A and B, the full solution set modulo is exactly
It remains to show this set has exactly distinct residues modulo , achieved by . First, these values are pairwise incongruent modulo : if with , then , so dividing by (a positive integer since ), we get ; but , forcing . Second, every value for arbitrary integer is congruent modulo to one with : write with (division algorithm), then
Hence the solution set modulo is precisely , a set of exactly distinct residues. This proves Part 2.
Part 3: the coprime case. If , then and Part 2 gives a unique solution modulo . By definition of Modular Inverses, since , Bezout's identity provides with , so ; thus is a modular inverse of . Multiplying by gives as a necessary condition on any solution, and substituting back in verifies , confirming it is indeed a solution. Combined with uniqueness from Part 2, this establishes Part 3.
∎Worked examples
Example 1: a coprime case forcing a genuine computation. Solve . Step 1 — check solvability. Compute via the Euclidean algorithm:
So . Since , the congruence is solvable, and by Part 3 of the theorem there is a unique solution modulo . Step 2 — back-substitute to find the inverse of mod . Reversing the Euclidean algorithm:
So , giving . Reducing gives ; check: . Indeed . So . Step 3 — solve. By Part 3,
Since , we get . Verification. , and indeed . So ✓, and this is the unique solution class modulo .
Example 2: a non-coprime case with , illustrating the full solution set. Solve . Step 1 — check solvability. Compute :
So . Since (indeed ), the congruence is solvable, and by Part 2 there are exactly incongruent solutions modulo . Step 2 — find one solution via Bezout. Back-substitute:
So . Since , multiply through by :
So satisfies . Check: , since . Confirmed. Step 3 — list all six solutions. By Part 2 the solutions are for , where :
So reducing mod 54, the complete solution set is
Verification of a couple of these: for : ✓ (since ). For : , and , since and ✓. Both check out, and one verifies similarly for . Notice the six solutions are exactly the residues spaced apart, matching from the theorem.
The theorem's Part 1 requires checking divides ; without this hypothesis the congruence can be flatly unsolvable, even though look otherwise unremarkable. Consider . Here , and . The theorem predicts no solution. Let's confirm directly by brute force, checking all nine residues :
The only values ever achieved by are — precisely the multiples of modulo — and is never among them. So indeed has no solution. This shows exactly what goes wrong if one attempts to apply the "unique solution via inverse" shortcut (Part 3) without first verifying or, more generally, without checking : has no inverse modulo at all (since ), so the formula is not even meaningful here, and one cannot bypass the divisibility check. The hypothesis is therefore not a technical nicety — it is the exact dividing line between solvable and unsolvable instances.
Scope, edge cases & common traps
| Situation | What happens |
|---|---|
| Unique solution mod ; use modular inverse | |
| , | Exactly solutions mod , spaced apart |
| , | No solution at all |
| , | Special case of above with : unsolvable unless |
| Every integer is a solution (only one residue class mod ) |
The mathematician behind it
Origins · 1 minCarl Friedrich Gauss and how this was discovered
Gauss systematized the theory of congruences in his 1801 treatise Disquisitiones Arithmeticae, introducing the notation still used today. He treated linear congruences as the natural starting point of modular arithmetic, building toward quadratic reciprocity and the arithmetic of Gaussian integers. His arithmetic viewpoint — replacing equations over with equivalence classes modulo — reframed number theory as the study of finite algebraic structures, laying groundwork later formalized as ring and group theory.
What's the difference between "no solution" and "infinitely many solutions"?
Over the integers, either has no integer solutions or has infinitely many integers satisfying it — but those infinitely many integers collapse into finitely many residue classes modulo . When we say "the congruence has solutions," we always mean distinct classes modulo , not literal integers. Any single class contains infinitely many representative integers (e.g., all count as "the same solution"). This convention matches how we treat the equation itself: since and satisfy identical congruences, they are not meaningfully different solutions.
Does the solvability criterion generalize to systems of several linear congruences?
Yes, and this is exactly the bridge to the Chinese Remainder Theorem. A system like , is solvable precisely when divides , and the CRT gives an explicit construction and shows the solution is unique modulo when the moduli are coprime. The single-congruence gcd criterion proved here is the base case that CRT-style arguments repeatedly invoke when combining more than two congruences.
How do I actually compute the modular inverse needed in Part 3?
Run the Euclidean algorithm on and to confirm , recording the quotients at each division step. Then back-substitute those steps in reverse order to express as for some integers — this is the extended Euclidean algorithm. The coefficient , reduced modulo , is the desired inverse . Example 1 above carries out this computation in full for , obtaining .
What if and share no common factor other than trivially, but itself is prime?
If is prime and , then automatically (since the only divisors of are and ), so Part 3 always applies: every nonzero residue modulo a prime has a unique inverse, and always has exactly one solution whenever . This is why for prime forms a field — every nonzero element is invertible — whereas for composite is only a ring with zero divisors.
Can or be negative, or larger than ?
Yes — the theorem places no restriction on the sign or size of and ; only is required. Negative values or values exceeding can always be reduced modulo first without changing the solution set, since and the divisibility condition only depends on . Reducing first is a matter of computational convenience, not mathematical necessity.
What happens when ?
If , the congruence becomes , i.e. . This fits the general theorem with : the criterion "" becomes "" exactly as expected, and when it holds, every integer is a solution, consistent with Part 2 predicting solutions modulo (all residues work).
Is the solution formula still valid if I only know some inverse of a, not the "canonical" one in [0,n)?
Yes. Any integer satisfying works identically in the formula, since the final answer is only claimed up to congruence modulo anyway. If and are both inverses of mod , they satisfy automatically (by the uniqueness part of the theorem applied to ), so regardless of which representative you use.