Modular arithmetic โ arithmetic on remainders. Given a divisor (or modulus) n, every integer is replaced by its remainder when divided by n, an integer in the range {0,1,โฆ,nโ1}.
Modulus / divisor $n$ โ the integer you divide by. On this tool, n ranges from 2 to 9 (the slice count).
Remainder โ the leftover after integer division. For a=qn+r with 0โคr<n, the remainder is r, written amodn=r.
Congruence $a \equiv b \pmod n$ โ read *a is congruent to b modulo n*. True when a and b leave the same remainder when divided by n, equivalently when n divides aโb.
Equivalence class / residue class โ the set of all integers sharing the same remainder. There are exactly n classes mod n, labeled [0],[1],โฆ,[nโ1].
Zero class (principal class) โ the class [0], containing 0 and all multiples of n. It's the identity element of the ring Z/nZ and corresponds to the principal ideal nZ. The tool highlights this class with a gold star and warm color.
$\mathbb{Z}/n\mathbb{Z}$ โ the integers mod n, the set of n equivalence classes with addition and multiplication inherited from Z.
Getting Started
The tool opens with divisor n=6 and a count target of 36. The scene splits into three areas:
โข A control panel on the left with inputs for the count target, the divisor (a button grid for n=2 through 9), a speed slider, and Run / Stop / Reset buttons.
โข A circular wheel in the middle, divided into n equal slices. Each slice is one remainder class. The zero class sits at the top (12 o'clock) marked with a gold star โ .
โข A context panel on the right that switches modes depending on what's happening: an *overview* before running, a *now placing* log while running, a *class details* card when you hover or pin a slice, and a *run complete* summary at the end.
To run:
โข Set the count target โ the number of integers to sort (1 through that target).
โข Pick a divisor in the grid.
โข Press โถ Run โ numbers 1,2,3,โฆ appear one at a time, each placed in its remainder slice with rows filling outward from the center.
โข Hover or click a slice to see its formula, examples, and any numbers already placed there.
โข Reset to clear and try a different combination.
mod 6, idle, frozen
Six empty slices around the mod 6 hub, the zero class starred at twelve oโclock. Nothing is placed yet โ the wheel is pure structure.
The frozen frame above is the idle wheel: six empty slices around the mod 6 hub, structure without content. Even empty, it already says something โ the modulus alone fixes how many classes exist, before a single number is sorted.
Idle is also the state to read the geometry in: slice labels outside, row arcs faint inside, and the starred zero slice at twelve o'clock. Once Run is pressed, the wheel anatomy fills in exactly these positions.
The Wheel and Slices
The wheel divides a circle into n equal slices, one per remainder class. Five things to watch:
โข Slice labels outside each slice show the remainder value: 0 at the top, then 1,2,โฆ,nโ1 going clockwise.
โข Slice colors use a blue palette so the zero class can stand apart. The zero slice has a warmer fill and a thin gold accent arc along its outer edge.
โข Rows within each slice run from the center outward โ row 1 is closest to the center, row 2 above it, and so on. Each row holds the next occurrence of that class.
โข Numbers in cells are drawn rotated so they always read upright relative to the slice they sit in. A label like *36* in slice 0 row 6 tells you 36=6โ 6+0, the sixth multiple of 6.
โข Center label shows *mod n* โ the modulus currently in effect.
Cells are placed in real time as the run progresses. The geometry adapts to the available width: bigger screens get a larger wheel with taller rows; smaller screens compress the row height. The control panel shows a max-count cap for the current divisor โ going beyond it would make labels unreadable.
Run Controls and Speed
The control panel offers three transport actions and a speed slider:
โข โถ Run โ starts placing numbers from 1 up to the count target, one per tick. Disabled while the input is invalid (empty, non-numeric, below 1, or above the geometric max).
โข โน Stop โ halts placement at the current number. The wheel keeps what's there; press Run again to start fresh from 1.
โข Reset โ clears all placed cells, unpins any class, and restores the idle state.
โข Speed slider with tortoise ๐ข and hare ๐ markers controls the tick delay. The tick interval is roughly max(20,400โ35โ speed) milliseconds โ at speed 1 each number takes about 365 ms; at speed 10 each takes about 50 ms.
While running, the right panel switches into *now placing* mode and shows live arithmetic for the most recent number: nรทd=q remainder r, and which slice and row it just landed in. Numbers in the zero class get extra emphasis to call out the divisibility.
mod 6, placing 17, frozen
Seventeen numbers in: 17 รท 6 = 2 remainder 5, so 17 has just landed in class 5, row 3 โ the third number to leave that remainder.
The frozen frame above catches a run mid-flight: seventeen numbers placed, and the log reporting 17รท6=2 remainder 5 โ so 17 has just landed in class 5, row 3. Rows count occurrences: 17 is the third number (after 5 and 11) to leave remainder 5.
Watching a few ticks makes the rhythm obvious: the placement simply walks around the wheel, one slice clockwise per number, wrapping back to the starred slice at every multiple. That steady rotation is the additive structure of equivalence classes in motion.
Hovering and Pinning Classes
Every slice on the wheel is interactive:
โข Hover any slice โ a floating tooltip appears showing the class title, formula, description, and example numbers. The right panel simultaneously switches into *class details* mode with the same information plus the list of numbers already placed in that class.
โข Click to pin the class โ the tooltip stays put, the slice darkens slightly, and the right panel keeps showing details until you click somewhere else (or click the same slice again to unpin).
โข Click anywhere outside any slice to clear the pin.
The tooltip layout adapts to viewport edges โ it flips to the left of the cursor when too close to the right edge and above when too close to the bottom. Pinned tooltips show a *๐ Pinned* indicator at the bottom; hover-only tooltips show *Tap to pin*.
The class details panel includes:
โข The formula โ n=nk for class 0, or n=nk+r for class r.
โข A *Placed so far* block listing every number from the current run that landed in this class, if any.
mod 6, class 2 pinned, frozen
The darkened slice collects 2, 8, 14, 20, 26, 32 โ every number of the form 6k + 2, each exactly six apart.
The frozen frame above has class 2 pinned after a full run of 36: the darkened slice holds 2, 8, 14, 20, 26, 32 โ six numbers, each exactly six apart. Pinning turns one wedge of the wheel into a statement: this is a single residue class, an arithmetic progression wrapped into a slice.
Pinning is also the way to compare classes: pin one, read its members, then pin its neighbor and watch every number shift by exactly one. The only slice that answers differently is the starred one โ see the zero class.
The Zero Class โ Why It's Special
Class [0] โ the multiples of n โ gets special visual treatment: it's centered at 12 o'clock, marked with a gold star โ , outlined with a warm-gold accent arc, and labeled prominently in the legend.
The emphasis is mathematical, not cosmetic. The zero class is the principal class:
โข It contains the integer 0, which is the additive identity of Z/nZ.
โข It's the only class where *divisibility by n* is true โ every member is an exact multiple of n.
โข Every other class is the zero class shifted: class [r]=[0]+r.
โข In ring theory it corresponds to the principal idealnZ.
โข It's the kernel of the canonical map ZโZ/nZ โ the integers that get sent to 0 under modular reduction.
For applications, the zero class is what you test for divisibility, what triggers modular conditions like *check if n is a multiple of 7*, and what determines whether a number has a multiplicative inverse in Z/nZ (nonzero residues coprime to n do; zero never does).
mod 6, zero class pinned, frozen
The gold-edged slice holds 6, 12, 18, 24, 30, 36 โ the multiples of 6, the only class where divisibility is true.
The frozen frame above has the principal class pinned after a full run: 6, 12, 18, 24, 30, 36 sit in the gold-edged slice โ the multiples of 6, and nothing else. Every divisibility question about 6 is a question about membership in this one slice.
The gold styling repays attention during a run, too: each time the placement crosses twelve o'clock, the number landing there is exactly a multiple of the modulus, and the *now placing* log flags it. Divisibility stops being a property you compute and becomes a place on the wheel.
Adjusting Divisor and Count
Two inputs control the size and shape of the wheel:
โข Count up to sets the upper bound of the integers placed during a run. Range starts at 1 and is capped per divisor by a geometric maximum โ the cap ensures rows fit at the minimum readable cell height. The cap appears below the input as *max for divisor n: M*. Common caps at default width: divisor 2 allows roughly 80 numbers, divisor 9 allows much more since rows are spread across more slices.
โข Divisor (number of slices) is an eight-button grid for n=2,3,4,5,6,7,8,9. Picking a new divisor immediately clears any in-progress run and re-divides the wheel. The wheel resizes and re-labels each slice.
Try these comparisons:
โข Divisor $2$ โ split into even and odd halves. Class 0 = evens, class 1 = odds.
โข Divisor $5$ โ slice r holds every integer whose last digit is r or r+5. The closest this wheel gets to reading off last digits directly (a mod-10 wheel would do it exactly, but the divisor grid stops at 9).
โข Divisor $7$ โ counting from 1 takes seven numbers to complete one row across all slices. Mimics the day-of-week shift.
โข Same number, different divisors โ keep the count fixed at 30 and step through divisors 2 to 9 to see how class sizes change.
mod 2, 20 placed, frozen
Two half-circles: evens in the starred half, odds opposite, ten each. Parity is the smallest modulus, drawn as a coin with two faces.
The frozen frame above is the divisor-2 wheel after counting to 20: two half-circles, evens in the starred half, odds opposite, ten numbers each. Parity โ the oldest classification in arithmetic โ is just modular arithmetic at its smallest modulus, and the wheel draws it as a coin with two faces.
Changing the divisor is the tool's most instructive move: the same integers exist either way, but the wheel repartitions them completely. Nothing about a number changes; only the question asked of it does. How the classes balance out at the end of a run is taken up under reading a complete run.
Right Panel Context
The right panel adapts to whichever phase the visualization is in:
โข Overview (idle) โ appears before the first run. Confirms which divisor is selected and prompts you to press Run.
โข Now placing (running) โ shows the most recent number, its division arithmetic (nรทd=q remainder r), which class it landed in, and which row within that class. Zero-class hits get a *divisible by n* accent.
โข Class details (hover/pin) โ appears whenever a slice is hovered or pinned. Shows the formula, first eight examples, and any run-placed numbers in this class.
โข Run complete (summary) โ appears after the count target is reached. Lists the divisible numbers in the zero class as the headline, then a grid showing the count per class.
Below the adaptive box sits a static deep-dive section with five collapsible-looking subsections: *What is modular arithmetic*, *Equivalence classes*, *The zero class โ why it's special*, *How to read this wheel*, and Try this. These are always available and don't change with state โ they're reference material to read alongside experimenting on the wheel.
Reading a Complete Run
When the last number lands, the right panel switches to its *run complete* summary: the divisible numbers โ the contents of the zero class โ as the headline, then a small grid counting the members of every class.
For the default run of 36 with divisor 6, the wheel finishes perfectly balanced: six full rows in every slice, exactly six numbers per class. That is no accident โ 36 is a multiple of 6, so the count 1 through 36 completes whole laps of the wheel.
The counts can never be lopsided by much. Counting 1 through N deals numbers to the slices in strict rotation, so any two classes differ by at most one member.
mod 6, run complete, frozen
All 36 numbers placed: six full rows in every slice, six per class โ perfectly balanced, because 36 is a multiple of 6.
The near-balance has a precise form. Write N=qn+r; then classes 1 through r hold q+1 numbers and the rest hold q. Try counting to 20 with divisor 6: classes 1 and 2 collect four members, every other class three โ and the zero class gets exactly โ20/6โ=3, namely 6, 12, 18.
This is the pigeonhole picture of equivalence classes: n boxes, dealt in rotation, can never be unfair by more than a single card. Change the divisor and rerun to watch the same fairness reassert itself over different slices.
What Is Modular Arithmetic
Modular arithmetic replaces each integer with its remainder when divided by a fixed modulus n. The result is always one of {0,1,โฆ,nโ1}, no matter how big the input.
The fundamental notation is congruence:
aโกb(modn)โบnโฃ(aโb)
That is, a and b are *congruent modulo n* when their difference is a multiple of n, equivalently when they leave the same remainder.
Examples:
โข Clock arithmetic is mod 12 (or mod 24). 14 o'clock โก2 o'clock (mod12).
โข Days of the week are mod 7. If today is Wednesday, day 100 from now is Wednesday +100mod7= Wednesday +2 = Friday.
โข Parity is mod 2. *Even* means โก0(mod2); *odd* means โก1(mod2).
โข Cryptography โ RSA, Diffie-Hellman, elliptic-curve protocols all operate in Z/pZ or Z/nZ for very large n.
โข Hashing and indexing โ converting arbitrary integers into a fixed range {0,โฆ,nโ1} is exactly modular reduction.
The operations of addition, subtraction, and multiplication on classes are well-defined: (a+b)modn=((amodn)+(bmodn))modn, and likewise for multiplication. Division (modular inverse) exists only when gcd(a,n)=1.
For deeper coverage, see the modular arithmetic section on the number theory page.
Equivalence Classes and Their Structure
For a fixed modulus n, the integers Z split into exactly n disjoint equivalence classes:
Z=[0]โ[1]โโฏโ[nโ1]
Each class [r] is the set {r+kn:kโZ} โ an infinite arithmetic progression spaced n apart on the number line.
Properties:
โข Every integer belongs to exactly one class.
โข Two integers are in the same class iff they're congruent mod n.
โข Class [r] contains negative numbers too: โ7โก5(mod12) because โ7+12=5.
โข Class sizes are infinite in Z; on the wheel they look finite only because we cut the count at the target.
The set of classes is a ring. Define [a]+[b]=[a+b] and [a]โ [b]=[aโ b] on representatives, then check the result doesn't depend on which representatives you picked. The result is the ring Z/nZ:
โข Always associative, commutative, with multiplicative identity [1].
โข A field exactly when n is prime โ then every nonzero class has a multiplicative inverse.
โข When n is composite, some classes are zero divisors: nonzero [a],[b] with [a]โ [b]=[0]. For instance, in Z/6Z, [2]โ [3]=[6]=[0].
The wheel visualizes the additive structure: shifting all numbers by +1 rotates everything one slice clockwise. Multiplicative structure is harder to picture but underlies most applications.
Related Concepts
Greatest common divisor (gcd) โ closely tied to modular arithmetic. The Euclidean algorithm computes gcd(a,b) using repeated modular reduction. An integer a has a multiplicative inverse mod n iff gcd(a,n)=1.
Euler's totient $\varphi(n)$ โ counts integers in {1,โฆ,nโ1} that are coprime to n. Equivalently, the number of invertible classes in Z/nZ. For prime n, ฯ(n)=nโ1.
Fermat's little theorem โ for prime p and a coprime to p: apโ1โก1(modp). Generalizes to Euler's theorem aฯ(n)โก1(modn).
Chinese Remainder Theorem โ if gcd(m,n)=1, the system xโกa(modm) and xโกb(modn) has a unique solution mod mn. Lets you reconstruct an integer from its residues in different moduli.
Modular exponentiation โ computing akmodn efficiently via repeated squaring. The core operation in RSA.
Discrete logarithm โ given g,h,n, find k with gkโกh(modn). Hard in general; security of Diffie-Hellman depends on it.
Quadratic residues โ integers that are squares mod n. Class [r] is a quadratic residue mod n if there exists x with x2โกr(modn).
Congruence equations โ solving axโกb(modn). Has a solution iff gcd(a,n) divides b.
Modulo calculator โ to compute amodn for arbitrary integers, see the modulo calculator.