Skip to content

Arithmetic Modulo $n$

Arithmetic modulo $n$ is arithmetic performed on residue classes modulo $n$. Instead of distinguishing all integers separately, we identify integers that have the same...

Modular Arithmetic

Arithmetic modulo nn is arithmetic performed on residue classes modulo nn. Instead of distinguishing all integers separately, we identify integers that have the same remainder after division by nn.

Thus, modulo nn, every integer is represented by one of

0,1,2,,n1. 0,1,2,\ldots,n-1.

For example, modulo 55,

72(mod5),133(mod5). 7\equiv2\pmod5, \qquad 13\equiv3\pmod5.

So in arithmetic modulo 55, the integer 77 behaves like 22, and the integer 1313 behaves like 33.

Addition Modulo nn

To add two residue classes modulo nn, add representatives and then reduce the result modulo nn.

For example, modulo 77,

5+6=114(mod7). 5+6=11\equiv4\pmod7.

Therefore,

[5]7+[6]7=[4]7. [5]_7+[6]_7=[4]_7.

The sum wraps around after reaching 77. This is why modular arithmetic is often called clock arithmetic. On a clock modulo 1212,

9+52(mod12). 9+5\equiv2\pmod{12}.

Subtraction Modulo nn

Subtraction works in the same way. Subtract first, then reduce modulo nn.

For example, modulo 99,

37=4. 3-7=-4.

Since

45(mod9), -4\equiv5\pmod9,

we have

375(mod9). 3-7\equiv5\pmod9.

Negative numbers cause no difficulty because every integer has a unique representative among

0,1,,n1. 0,1,\ldots,n-1.

Multiplication Modulo nn

Multiplication modulo nn is defined by

[a]n[b]n=[ab]n. [a]_n[b]_n=[ab]_n.

For example, modulo 88,

57=353(mod8). 5\cdot7=35\equiv3\pmod8.

Thus

[5]8[7]8=[3]8. [5]_8[7]_8=[3]_8.

Multiplication modulo nn is associative, commutative, and distributive over addition, because these laws hold for ordinary integers and congruence respects arithmetic.

Powers Modulo nn

Powers are repeated multiplication modulo nn. They are computed by reducing intermediate results.

For example, modulo 1010,

313, 3^1\equiv3, 329, 3^2\equiv9, 33277, 3^3\equiv27\equiv7, 34211. 3^4\equiv21\equiv1.

After that, the pattern repeats:

353,369. 3^5\equiv3, \qquad 3^6\equiv9.

Such periodic behavior is common in modular arithmetic.

Additive Identity and Additive Inverses

The class

[0]n [0]_n

is the additive identity because

[a]n+[0]n=[a]n. [a]_n+[0]_n=[a]_n.

Every class has an additive inverse. The inverse of [a]n[a]_n is

[a]n. [-a]_n.

For example, modulo 77, the additive inverse of [3]7[3]_7 is [4]7[4]_7, since

3+4=70(mod7). 3+4=7\equiv0\pmod7.

Thus addition modulo nn behaves like addition in a finite cyclic system.

Multiplicative Identity and Units

The class

[1]n [1]_n

is the multiplicative identity:

[a]n[1]n=[a]n. [a]_n[1]_n=[a]_n.

However, not every nonzero residue class has a multiplicative inverse.

A class [a]n[a]_n has a multiplicative inverse modulo nn if there exists a class [b]n[b]_n such that

[a]n[b]n=[1]n. [a]_n[b]_n=[1]_n.

Equivalently,

ab1(modn). ab\equiv1\pmod n.

This occurs exactly when

gcd(a,n)=1. \gcd(a,n)=1.

For example, modulo 88,

33=91(mod8), 3\cdot3=9\equiv1\pmod8,

so [3]8[3]_8 is its own inverse.

But [2]8[2]_8 has no inverse because

gcd(2,8)=2. \gcd(2,8)=2.

Zero Divisors

A nonzero residue class [a]n[a]_n is called a zero divisor if there exists a nonzero class [b]n[b]_n such that

[a]n[b]n=[0]n. [a]_n[b]_n=[0]_n.

For example, modulo 66,

[2]6[3]6=[6]6=[0]6. [2]_6[3]_6=[6]_6=[0]_6.

Thus [2]6[2]_6 and [3]6[3]_6 are zero divisors.

Zero divisors occur precisely because 66 is composite. In contrast, modulo a prime pp, there are no zero divisors among nonzero classes.

Prime Moduli

When the modulus pp is prime, arithmetic modulo pp has especially good behavior.

Every nonzero class modulo pp has a multiplicative inverse. Indeed, if

1ap1, 1\le a\le p-1,

then

gcd(a,p)=1. \gcd(a,p)=1.

Therefore [a]p[a]_p is a unit.

The set

Z/pZ \mathbb{Z}/p\mathbb{Z}

is then a finite field. This means addition, subtraction, multiplication, and division by nonzero elements are all possible.

For example, modulo 55,

[2]51=[3]5, [2]_5^{-1}=[3]_5,

because

23=61(mod5). 2\cdot3=6\equiv1\pmod5.

Composite Moduli

When nn is composite, the arithmetic of Z/nZ\mathbb{Z}/n\mathbb{Z} is more complicated.

Some nonzero classes may fail to have inverses, and some may be zero divisors.

For example, modulo 1212,

[5]12 [5]_{12}

is a unit because

gcd(5,12)=1. \gcd(5,12)=1.

But

[4]12 [4]_{12}

is not a unit because

gcd(4,12)=4. \gcd(4,12)=4.

Also,

[3]12[4]12=[12]12=[0]12, [3]_{12}[4]_{12}=[12]_{12}=[0]_{12},

so both [3]12[3]_{12} and [4]12[4]_{12} are zero divisors.

Role in Number Theory

Arithmetic modulo nn is one of the central tools of number theory. It reduces questions about infinitely many integers to questions about a finite set of residue classes.

This makes many problems tractable. Congruences can test divisibility, solve equations, analyze powers, study primes, and construct cryptographic systems.

The passage from integers to

Z/nZ \mathbb{Z}/n\mathbb{Z}

is therefore a fundamental move: it replaces global arithmetic by finite arithmetic while preserving the divisibility information encoded by the modulus.