Modulo Calculator
Calculate the remainder of a division operation (a mod b) with the quotient.
Results update as you type.
How it works
The modulo operation (often written as %, mod, or a mod b) returns the remainder when dividing one number by another. For example, 17 mod 5 = 2, because 17 = 5 × 3 + 2 (five goes into 17 three times, with 2 left over). Modulo is one of the most fundamental operations in programming and number theory. In code, it's typically the % operator. It's used constantly in everyday programming: determining if a number is even (n % 2 == 0), wrapping around arrays (index = i % length), clock arithmetic (hours = (current + elapsed) % 12), and color cycling in UIs. In mathematics, modular arithmetic (working with remainders) is the foundation of cryptography. The RSA encryption algorithm, which secures most internet communications, is built entirely on modular exponentiation. The last digits of large exponential calculations, determined by mod, create the one-way functions that make encryption secure. Modulo also appears in checksum algorithms (credit card number validation), hash functions, random number generators, and scheduling problems. Whenever a value must wrap within a fixed range — an hour on a clock, a day of the week, a pixel column, or a slot in a hash table — the modulo operation is usually the cleanest way to express that wrap-around in a single step.
a mod b = a − b × ⌊a/b⌋; Quotient = ⌊a/b⌋
Division splits a into a whole-number quotient and a leftover part. The floor of a/b is how many complete times b fits inside a, and multiplying that quotient back by b and subtracting it from a leaves exactly what could not be evenly divided — the remainder. This guarantees the identity a = b × quotient + remainder, with the remainder always smaller in size than the divisor b.
Source:Standard mathematical definition
We review all our tools from time to time to ensure accuracy.
Worked example
How to use this calculator
- 1
Enter your values
Enter dividend (a) and divisor (b).
- 2
Adjust the options
Fine-tune any options to match your situation.
- 3
Read your result
Remainder (a mod b) updates instantly as you type — no button to press.
Frequently asked questions
What is modulo used for in programming?
Modulo is one of the most frequently used operations in programming. Common uses include: checking if a number is even or odd (n % 2 == 0 means even); wrapping indices for circular data structures (array[i % length] cycles through an array indefinitely); clock arithmetic (hour = (current_hour + hours_to_add) % 12); generating repeating patterns; implementing hash tables (hash % table_size maps any hash to a valid index); and creating cycles in animations (frame % total_frames). It's also central to cryptographic algorithms.
How does modulo work with negative numbers?
Modulo with negative numbers can give different results depending on the programming language or mathematical convention used. In most mathematical contexts, the result has the same sign as the divisor (b). In Python: −7 mod 3 = 2. In C/Java/JavaScript, % gives the remainder with the sign of the dividend: −7 % 3 = −1. Our calculator uses the mathematical floor-based definition. The two are equivalent for positive numbers; for negative numbers, adjust with: if (result < 0) result += b to get the positive modulo.
What is modular arithmetic?
Modular arithmetic is a system of integer arithmetic where numbers 'wrap around' upon reaching a certain value (the modulus). On a 12-hour clock, after 12 comes 1 (not 13) — that's mod 12. Days of the week cycle mod 7. Modular arithmetic follows its own algebra: you can add, subtract, and multiply numbers modulo m, and the results stay within 0 to m−1. This system has deep applications in cryptography, computer science, calendaring algorithms, and abstract algebra (group theory and ring theory).
What is the difference between modulo and remainder?
For positive numbers, modulo and remainder are the same. The distinction arises with negative numbers. The mathematical modulo operation (used in number theory) always returns a non-negative result in [0, b−1]. The programming remainder (%) typically returns a result with the same sign as the dividend. For example: −7 mod 3 = 2 (mathematical), but −7 % 3 = −1 (C-style remainder). Both are useful; the mathematical modulo is preferred in cryptography and number theory, while the C-style remainder is what most programming languages implement with %.
How is modulo used in cryptography?
Modular arithmetic is the mathematical backbone of modern cryptography. RSA encryption uses modular exponentiation: given large primes p and q, their product n = pq creates a 'trapdoor' — it's easy to compute m^e mod n (encrypt), but computationally infeasible to reverse without knowing the private key. The Diffie-Hellman key exchange uses discrete logarithms in modular arithmetic. AES encryption uses operations in a finite field (arithmetic modulo an irreducible polynomial). Without modular arithmetic, public-key cryptography — and therefore secure web browsing, banking, and messaging — would not be possible.
Related calculators
Factorial Calculator (n!)
Calculate the factorial of any non-negative integer. See results for large values too.
Combinations Calculator (nCr)
Calculate the number of ways to choose r items from a set of n items, where order doesn't matter.
Percentage Calculator
Find what X% of a number is, instantly.