Home › Math & Science › Modulo Calculator
Modulo Calculator
Use this free modulo calculator to find the remainder after division, the quotient, and the full step-by-step working. It also has a modular inverse mode that finds the number x with a·x ≡ 1 (mod m) using the extended Euclidean algorithm — or tells you clearly when no inverse exists.
Whole numbers work best. Decimals are allowed in modulo mode; the inverse mode needs whole numbers.
| Step | Value |
|---|---|
| Dividend (a) | 17 |
| Divisor (b) | 5 |
| Quotient (q) | 3 |
| Remainder (r) | 2 |
| Check: q × b + r | 3 × 5 + 2 = 17 |
How it works
Division usually answers how many whole groups fit into a number. The modulo operation answers the opposite question: after taking away as many whole groups as possible, what is left? If you have 17 cookies and pack them in boxes of 5, you fill 3 boxes and have 2 cookies left over. The quotient is 3, the remainder is 2, and we write 17 mod 5 = 2. Every division can be written in the same shape: dividend = quotient × divisor + remainder, or a = q × b + r, with the remainder always smaller than the divisor.
To find the remainder by hand, divide and keep the whole-number part as the quotient, then multiply the quotient back by the divisor and subtract from the dividend. For 17 ÷ 5, the whole-number part is 3, 3 × 5 is 15, and 17 − 15 is 2. That subtraction step is the whole trick, and it is also the step this calculator shows you, so you can check its work instead of trusting a black box.
Negative numbers are where modulo gets interesting, because two different conventions exist. This calculator uses the mathematical convention, also called floored division: the remainder always takes the sign of the divisor. With a positive divisor, the remainder is always between 0 and the divisor minus 1. So −17 mod 5 is 3, not −2, because −17 = (−4) × 5 + 3. That is the convention mathematicians use, and it is the one that makes clock arithmetic work. Some programming languages use a different convention, called truncated division, where the remainder keeps the sign of the dividend — in JavaScript, −17 % 5 is −2. Both answers describe the same division; they just split the leftover differently. If your code gives −2 where this calculator gives 3, neither is wrong — they are different conventions, and this page states which one it uses.
The modular inverse mode solves a different problem: given a and m, find the number x such that a·x leaves a remainder of 1 when divided by m. We write that as a·x ≡ 1 (mod m). For example, the inverse of 3 modulo 7 is 5, because 3 × 5 = 15 and 15 mod 7 = 1. The calculator finds x with the extended Euclidean algorithm, a method that works backward through the steps of Euclid's algorithm for the greatest common divisor. An inverse exists only when a and m are coprime — when their greatest common divisor is 1. If they share a factor, no inverse exists: for instance, 4 has no inverse modulo 6, because every multiple of 4 is even, and no even number leaves a remainder of 1 when divided by 6. When that happens, the calculator says so and shows the gcd it found, instead of inventing an answer.
Modulo arithmetic is far more than a classroom exercise. The 12-hour clock is modulo 12: 13 o'clock is 1 o'clock because 13 mod 12 = 1. The day of the week for any date is a modulo 7 calculation. Check digits on credit cards and barcodes are modulo checks that catch typing mistakes. Computer programs use modulo to spread data evenly across hash tables, and modern encryption is built on modular inverses. Once you can see the remainder clearly, a surprising amount of everyday and digital life turns out to be clock arithmetic.
To use the calculator, choose the mode, enter your numbers, and read the result. In modulo mode, decimals are allowed, and the step table shows the quotient, the remainder, and the check that q × b + r really equals your dividend. In inverse mode, enter whole numbers for a and m, and the calculator returns the smallest positive inverse, along with the gcd. A divisor of zero is not allowed in either mode, and the calculator will say so instead of showing a confusing result.
Worked example
Find 17 mod 5, and then find the modular inverse of 3 modulo 7.
Step 1: Divide 17 by 5. The whole-number part is 3, so the quotient q = 3.
Step 2: Multiply back: 3 × 5 = 15.
Step 3: Subtract: 17 − 15 = 2, so the remainder r = 2. Check: 17 = 3 × 5 + 2. Therefore 17 mod 5 = 2.
Step 4: For the inverse, we need x with 3x ≡ 1 (mod 7). Try the multiples of 3 modulo 7: 3 × 1 = 3, 3 × 2 = 6, 3 × 3 = 9 ≡ 2, 3 × 4 = 12 ≡ 5, 3 × 5 = 15 ≡ 1. So x = 5.
Step 5: Check the inverse: 3 × 5 = 15, and 15 = 2 × 7 + 1, so 15 mod 7 = 1. The gcd of 3 and 7 is 1, which is why an inverse exists.
So 17 mod 5 = 2 with quotient 3, and the modular inverse of 3 modulo 7 is 5. Try both in the calculator: enter 17 and 5 in modulo mode, then switch to inverse mode and enter 3 and 7. You will get the same answers, with the working shown.
FAQ
What is the modulo operation?
The modulo operation finds the remainder after division. For example, 17 mod 5 is 2, because 17 divided by 5 is 3 with 2 left over. It answers the question of what is left after taking away as many whole groups of the divisor as possible.
What is the modulo of a negative number?
This calculator uses the mathematical convention: the remainder always has the same sign as the divisor, so with a positive divisor the result is always between 0 and the divisor minus 1. For example, −17 mod 5 is 3, because −17 equals −4 × 5 + 3. Some programming languages instead give −2, keeping the sign of the dividend.
What is a modular inverse?
A modular inverse of a modulo m is a number x such that a times x leaves a remainder of 1 when divided by m. For example, the inverse of 3 modulo 7 is 5, because 3 × 5 equals 15, and 15 mod 7 is 1. Modular inverses are used in cryptography and in solving congruences.
When does a modular inverse not exist?
A modular inverse of a modulo m exists only when a and m share no common factor other than 1 — that is, when their greatest common divisor is 1. If gcd(a, m) is not 1, no number x can make a times x leave a remainder of 1, and this calculator says so plainly.
What is the modulo used for in real life?
Modulo arithmetic runs the 12-hour clock, where 13 o'clock is 1 o'clock because 13 mod 12 is 1. It also powers check digits on cards and barcodes, hashing in computer programs, the day-of-the-week calculation for a date, and the encryption that keeps online messages private.