Modular arithmetic is a system of arithmetic in which integers are compared and combined according to their remainders upon division by a fixed positive integer, called the modulus. Numbers differing by a multiple of the modulus are treated as equivalent. This produces “wraparound” calculations rather than an indefinitely increasing number line. Modular arithmetic provides a basic language for number theory and underlies important constructions in cryptography. (cs.cornell.edu)
Congruence and remainders
For a positive integer , the notation
means that divides , or equivalently that for some integer . Thus , because their difference is . Negative integers also have residues: . The statement describes a relationship between integers, not ordinary equality between them. (cs.cornell.edu)
By division with remainder, every integer has a unique expression , where . The number is its least nonnegative residue modulo . Consequently, congruent integers have the same remainder. The expression usually denotes this particular remainder, whereas “” in a congruence specifies the relation being used. (cs.cornell.edu)
A twelve-hour clock illustrates the idea: advancing five hours from ten gives three, since . The clock label twelve represents residue zero. This analogy explains wraparound addition, although the mathematical system also supports multiplication and more general algebraic operations. (pi.math.cornell.edu)
Arithmetic rules
Congruences respect addition, subtraction, and multiplication. If and , then
Intermediate results may therefore be reduced modulo without changing the final residue. For example, modulo seven, . Reducing first often makes calculations substantially smaller. (cs.cornell.edu)
Repeated multiplication also gives for every nonnegative integer . These rules extend to evaluating any polynomial with integer coefficients. However, exponents cannot generally be reduced modulo the same modulus: , whereas . Exponent reduction requires separate conditions and theorems. (cs.cornell.edu)
Residue classes and algebraic structure
Congruence modulo is an equivalence relation: it is reflexive, symmetric, and transitive. It partitions the integers into residue classes. The class containing is
The collection of classes is denoted , also written . Addition and multiplication are defined by and ; the congruence rules ensure that the definitions do not depend on the chosen representatives. (cs.cornell.edu)
In abstract algebra, this structure is a commutative ring with identity. Its additive structure is a cyclic group, connecting it with group theory. If is a prime number, every nonzero class is invertible, so the ring is a field, specifically a finite field with elements. Composite moduli instead admit nonzero classes whose product is zero: modulo six, . (cs.cornell.edu)
Inverses and linear congruences
A modular multiplicative inverse of is an integer satisfying . It exists exactly when the greatest common divisor equals one. The extended Euclidean algorithm finds integers satisfying ; reducing this identity modulo gives the inverse. For instance, three has inverse five modulo seven. (math.stanford.edu)
Division therefore means multiplication by an inverse, not ordinary integer division. Cancellation can fail when the factor is not invertible: , but . More generally, cancelling changes the modulus to . (cs.cornell.edu)
A linear congruence has a solution precisely when divides . When solvable, it has exactly distinct solutions modulo . For example, has the two solutions and . These facts follow by applying the inverse criterion after dividing the coefficients and modulus by . (math.stanford.edu)
Fundamental theorems
Fermat’s little theorem states that for prime . If does not divide , this becomes . Euler’s theorem generalizes the latter statement:
Here Euler’s totient function counts the integers from one through that are relatively prime to . (math.stanford.edu)
The Chinese remainder theorem combines congruences with pairwise coprime moduli. Given , it guarantees one solution class modulo . Thus and together give . (math.stanford.edu)
Historical development and applications
Carl Friedrich Gauss presented a systematic treatment of congruences in Disquisitiones Arithmeticae, published in 1801. Its opening sections address congruences generally, linear congruences, and residues of powers, establishing the framework for subsequent investigations. (e-rara.ch)
In computer science, modular calculations support hash-table indexing, check digits, and pseudorandom sequences. They also explain decimal divisibility tests: because , an integer is congruent modulo nine to the sum of its digits. (cs.cornell.edu)
The RSA cryptosystem uses modular exponentiation with a modulus formed from two primes. Its basic mathematical transformation is , with a related private exponent reversing the transformation. Secure encryption requires additional encoding and padding mechanisms beyond this arithmetic operation. (cs.cornell.edu)