The modulo operation returns the remainder left over after dividing one integer by another. Written A mod M, it answers a simple question: "if I divide A by M as many whole times as possible, what's left?" 17 mod 5 is 2, because 5 fits into 17 three whole times (15), leaving a remainder of 2. That small remainder turns out to be one of the most useful numbers in mathematics and computer science — it's the basis of clock arithmetic, cyclic numbering, hashing, and much of modern cryptography.
What modulo means, how it behaves with negative numbers, and where it powers real software and cryptography.
Modulo is an arithmetic operation that returns the remainder after dividing one number by another. When you write "A mod M," you're asking for whatever is left over once M has been subtracted from A as many whole times as possible. 17 mod 5 equals 2, because 5 goes into 17 three full times (making 15), leaving 2 behind. The result of a modulo operation is always non-negative and always smaller than the divisor (when using the mathematical, positive convention this calculator follows).
In everyday use, "modulo" and "remainder" mean the same thing for positive numbers. They diverge only with negative inputs: some programming languages' built-in "%" operator returns a result with the same sign as the dividend (a true "remainder" operator), while the mathematical modulo operation always returns a non-negative result between 0 and M−1. This calculator implements true positive modulo, which is why −13 mod 5 correctly returns 2, not −3.
Every modulo calculation rests on one identity from basic number theory: Dividend = Divisor × Quotient + Remainder. Given 17 and 5, the quotient is 3 and the remainder is 2, and indeed 5 × 3 + 2 = 17. This equation is exactly the verification shown alongside every Basic Modulo result — if it doesn't balance, the calculation is wrong.
The quotient is how many whole times the divisor fits into the dividend; the remainder is what's left afterward. For positive numbers this matches ordinary long division. The quotient used in this calculator's positive-modulo convention is the floor of the division — rounded down toward negative infinity — which is what guarantees the remainder always comes out non-negative, even when the dividend is negative.
When both the dividend and divisor are positive, modulo behaves exactly like ordinary remainder-after-division: 10 mod 3 = 1, 18 mod 5 = 3, 21 mod 7 = 0. These are the cases most people learn first, and they form the baseline for understanding the trickier negative case below.
Negative numbers are where modulo conventions diverge and where most confusion happens. Under the mathematical (positive) convention, −13 mod 5 = 2, not −3. The reasoning: −13 = 5 × (−3) + 2, so the quotient is −3 and the remainder is 2 — a valid, non-negative remainder smaller than the divisor. This calculator always applies that positive convention, using the formula ((A % M) + M) % M to correct for any negative intermediate result.
Two integers are said to be "congruent modulo M" if they leave the same remainder when divided by M — written A ≡ B (mod M). For example, 17 and 2 are congruent modulo 5, because both leave a remainder of 2. Congruence is the foundation of modular arithmetic as a formal system, letting mathematicians treat entire families of numbers as equivalent for a given modulus.
Modular arithmetic performs addition, subtraction, and multiplication as usual, then reduces the result modulo M at the end — (A + B) mod M, (A − B) mod M, and (A × B) mod M. This is exactly how a 12-hour clock works: 9 + 5 = 14, but on a clock that reads as 2, because 14 mod 12 = 2. The same wraparound logic governs array indexing, circular buffers, and cyclic scheduling in software.
A modular inverse of a number A, with respect to modulus M, is a number B such that (A × B) mod M = 1 — essentially, "division" within modular arithmetic. Modular inverses exist only when A and M share no common factors, and finding them is a key step in several cryptographic algorithms, including parts of RSA key generation.
Modular exponentiation computes A^B mod M — but computing A^B directly first and then reducing it modulo M becomes impossibly slow for large exponents, since A^B can have thousands of digits. Fast modular exponentiation (also called exponentiation by squaring) avoids this by repeatedly squaring the base and reducing modulo M at every step, using the exponent's binary representation to decide when to multiply the running result. This turns an operation that would otherwise take exponential time into one that takes only about log₂(B) multiplications — the exact technique this calculator uses under the hood.
A standard clock is the most intuitive real-world example of modular arithmetic: hours wrap around every 12 (or 24), which is precisely addition modulo 12 (or modulo 24). Days of the week wrap around modulo 7. Any cyclic counting system — including compass headings modulo 360 — is a direct application of the same modulo operation this calculator performs.
Modular arithmetic is central to number theory, particularly in studying prime numbers. Fermat's Little Theorem and related results, which underpin much of modern cryptography, are statements about how numbers behave modulo a prime. Modular exponentiation is the computational engine that makes these theorems practically useful rather than purely theoretical.
Programmers use modulo constantly: wrapping an array index back into range with index mod length, alternating behavior every Nth iteration with i mod N === 0, converting between units (seconds mod 60 for a clock display), and detecting even or odd numbers with n mod 2. It's one of the most frequently used operators in everyday software development.
Public-key cryptography systems like RSA rely entirely on modular exponentiation: encrypting and decrypting a message both involve raising a number to a power modulo a large composite number. The security of the whole system depends on modular exponentiation being fast to compute in one direction but effectively impossible to reverse without the private key — which is exactly why efficient fast exponentiation matters both for legitimate encryption and for understanding its security properties.
Many hash functions reduce a large intermediate number down to a fixed-size bucket using modulo, spreading values evenly across a hash table. Classic pseudorandom number generators, such as the linear congruential generator, are built directly on modular arithmetic — each new "random" number is generated by multiplying, adding, and then reducing the previous one modulo some fixed value.
Circular buffers — a common data structure in networking and audio/video streaming — use modulo to wrap a write position back to the start once it reaches the end of the buffer. Calendar systems use modulo to compute the day of the week for any date, and scheduling systems use it to cycle staff through repeating shift patterns.
Competitive programming problems frequently ask for an answer "modulo 10^9 + 7" specifically because the true answer would otherwise overflow standard integer types. Fast modular exponentiation and modular arithmetic identities are essential tools for solving these problems efficiently within strict time limits.
The most frequent errors are confusing modulo with plain division (they return different things — a remainder, not a quotient), confusing the mod operator with a percentage sign, mishandling negative dividends by expecting a negative result instead of the correct positive remainder, dividing by a zero modulus, forgetting to reduce intermediate results in a multi-step modular calculation, and letting numbers overflow before an exponentiation is reduced by fast exponentiation. Careful, step-by-step reduction — exactly what this calculator displays — avoids all of these.
Four steps between opening the page and having a verified, step-by-step modular result.
Pick Basic Modulo, Modular Addition, Modular Subtraction, Modular Multiplication, or Modular Exponentiation.
Dividends, divisors, moduli, bases, and exponents all accept positive and negative integers where mathematically valid.
The calculator applies a custom positive-modulo function and fast modular exponentiation to compute results instantly, even for large exponents.
Each result includes the verification equation and step-by-step working, useful for coursework, debugging, or explaining cryptographic concepts.
The core equations behind every mode of this calculator.
The basic modulo operation returns what's left after dividing the dividend by the divisor as many whole times as possible.
The division algorithm — this identity is used to verify every Basic Modulo result.
Modular addition, subtraction, and multiplication perform the operation as usual, then reduce the result modulo M.
Modular exponentiation, computed efficiently with fast exponentiation by squaring rather than computing A^B directly.
Six worked examples covering basic modulo, negative numbers, and every modular operation.
Common modulo results, modular operation formulas, and real-world applications.
| Expression | Result |
|---|---|
| 10 mod 3 | 1 |
| 15 mod 4 | 3 |
| 18 mod 5 | 3 |
| 21 mod 7 | 0 |
| 25 mod 6 | 1 |
| 30 mod 8 | 6 |
| Operation | Formula |
|---|---|
| Addition | (A+B) mod M |
| Subtraction | (A−B) mod M |
| Multiplication | (A×B) mod M |
| Exponentiation | A^B mod M |
| Industry | Example |
|---|---|
| Programming | Array index wrapping |
| Cryptography | RSA encryption |
| Networking | Hash functions |
| Databases | Data partitioning |
| Gaming | Circular maps |
| Mathematics | Number theory |
Why students, programmers, and cryptography professionals reach for a dedicated tool.
Addition, subtraction, multiplication, and exponentiation are all supported in one tool.
Correctly applies the mathematical positive-modulo convention for negative dividends.
Computes A^B mod M efficiently, even for large exponents, without overflow.
Results update instantly as you type — no separate submit step required.
Every result includes the working and verification equation, not just the final number.
Works cleanly on phones and tablets for coursework, debugging, or quick lookups.
Where modulo and modular arithmetic show up across software, security, and mathematics.
Computer programming uses modulo constantly for array index wrapping, alternating logic, and unit conversion. Cryptography and cybersecurity rely on modular exponentiation as the computational core of RSA and related encryption schemes. Networking and database indexing use modulo to distribute data evenly across hash buckets or partitions. Blockchain systems use modular arithmetic in cryptographic signatures and proof-of-work calculations. Game development uses modulo for circular maps, cyclic animations, and wraparound logic. Embedded systems use it for circular buffers and timing wraparound. Mathematics education and competitive programming both lean heavily on modular arithmetic and fast exponentiation, and artificial intelligence and algorithm optimization use modular reduction to keep intermediate values bounded during large-scale computation.
Avoid these to keep every modular calculation and every line of code correct.
Modulo returns the remainder, not the quotient — 17 mod 5 is 2, not 3.4.
The "%" symbol means modulo in most programming languages, not "percent" — a common beginner mix-up.
Some languages return a negative remainder for a negative dividend — always confirm which convention you need.
Dividing or taking modulo by zero is undefined and will always produce an error.
In a multi-step modular calculation, reduce after every operation to avoid unnecessarily large intermediate numbers.
Computing A^B directly before taking mod M can overflow — use fast modular exponentiation instead.
(A+B) mod M is not the same as A mod M plus B mod M unless you reduce the sum again afterward.
Standard integer types can overflow during multiplication or exponentiation before the modulo is applied — reduce early and often.
Common questions about modulo, modular arithmetic, and this calculator.
Modulo is the remainder left over after dividing one integer by another. 17 mod 5 = 2, because 5 goes into 17 three times with 2 left over.
For positive numbers they're identical. For negative numbers, mathematical modulo always returns a non-negative result, while some programming "%" operators return a signed remainder instead.
Divide the dividend by the divisor, take the whole-number quotient, multiply it back by the divisor, and subtract that from the dividend — what's left is the modulo result.
This calculator returns the correct positive result — for example, −13 mod 5 = 2 — using the mathematical positive-modulo convention.
Dividing by zero is undefined in mathematics, so a zero divisor or modulus always produces a validation error instead of a result.
It's arithmetic performed within a fixed modulus — addition, subtraction, and multiplication are carried out as usual, then reduced modulo M, similar to how a clock wraps around.
It's raising a base to a power and reducing the result modulo M, computed efficiently with fast exponentiation by squaring rather than by computing the full power first.
Common uses include wrapping array indices, alternating logic every N iterations, and converting units like seconds into minutes and seconds.
Public-key systems like RSA depend on modular exponentiation, which is fast to compute forward but effectively impossible to reverse without a private key.
Yes — whenever the dividend divides evenly into the divisor, such as 21 mod 7 = 0.
Not with the mathematical positive-modulo convention this calculator uses — results always fall between 0 and one less than the modulus.
Yes. It implements a custom positive modulo function and a manually written fast modular exponentiation algorithm, verified against the division algorithm for every result.
Yes, this modulo calculator is free to use with no signup required.
Yes, the layout and inputs are designed to work smoothly on phones and tablets.
Students, programmers, engineers, mathematicians, cybersecurity professionals, and competitive programmers who need fast, verified modular arithmetic results.
Calculate remainders, modular arithmetic, and modular exponentiation with this free professional calculator built for mathematics, programming, engineering, and cryptography.