About the Modular Arithmetic Calculator
What is the Modular Arithmetic Calculator?
Modular arithmetic is arithmetic that “wraps around” after reaching a fixed number, the modulus. a mod m is the remainder when a is divided by m: 17 mod 5 = 2. A 12-hour clock is the everyday example — 5 hours after 10 o'clock is 3 o'clock, because 15 mod 12 = 3.
Besides the remainder, the calculator finds aᵉ mod m using fast square-and-multiply exponentiation (so exponents up to a trillion are instant) and the modular inverse — the number x with a × x ≡ 1 (mod m) — using the extended Euclidean algorithm. These are the building blocks of RSA encryption.
How to use the Modular Arithmetic Calculator
- Number (a) — any whole number; negatives are allowed. (sample: 17)
- Modulus (m) — a positive whole number. (sample: 5)
- Exponent for aᵉ mod m — the exponent used for aᵉ mod m. (sample: 3)
- Press Calculate (results also refresh as you type). The result card shows the a mod m, along with aᵉ mod m, Modular inverse of a and Quotient (a ÷ m, floored).
Formula used
a mod m = a − m × ⌊a ÷ m⌋
- ⌊ ⌋ = rounding down to the nearest whole number
- m = the modulus (a positive whole number)
The result is always between 0 and m − 1, even for negative a (−7 mod 5 = 3). A modular inverse exists only when a and m have no common factor, i.e. GCD(a, m) = 1.
Worked example
These are the sample values already filled in the calculator above, and the result it returns for them:
| Input | Sample value |
|---|---|
| Number (a) | 17 |
| Modulus (m) | 5 |
| Exponent for aᵉ mod m | 3 |
| Result | Value |
|---|---|
| a mod m | 2 |
| aᵉ mod m | 3 |
| Modular inverse of a | 3 |
| Quotient (a ÷ m, floored) | 3 |
Tips for using the Modular Arithmetic Calculator
- Day-of-week problems: 100 days after a Monday is 100 mod 7 = 2 days later in the week — a Wednesday.
- ISBN-10 check digits use mod 11, and debit/credit card numbers are validated with the Luhn (mod 10) check.
- In many programming languages the % operator returns a negative result for negative inputs; this calculator always returns a value from 0 to m − 1.
