COC

Free Online Tool

Modulo Calculator

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.

  • No signup required
  • Handles negative numbers correctly
  • Fast modular exponentiation
  • Mobile friendly
Enter a valid integer
Cannot be zero
Enter a valid integer
Enter a valid integer
Must be greater than zero
Enter a valid integer
Enter a valid integer
Must be greater than zero
Enter a valid integer
Enter a valid integer
Must be greater than zero
Enter a valid integer
Must be a non-negative integer
Must be greater than zero

The Complete Guide to Modulo and Modular Arithmetic

What modulo means, how it behaves with negative numbers, and where it powers real software and cryptography.

What does modulo mean?

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).

Modulo vs. remainder — are they the same thing?

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.

The division algorithm

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.

Quotients and remainders

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.

Positive modulo

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 modulo

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.

Congruence relations

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

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.

Modular inverse

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 and the fast exponentiation algorithm

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.

Clock arithmetic

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.

Number theory and prime numbers

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.

Applications in programming

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.

Cryptography and encryption

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.

Hash functions and random number generators

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, calendars, and scheduling

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

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.

Common mistakes when working with modulo

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.

How the Calculator Works

Four steps between opening the page and having a verified, step-by-step modular result.

1

Choose a Calculation Type

Pick Basic Modulo, Modular Addition, Modular Subtraction, Modular Multiplication, or Modular Exponentiation.

2

Enter Integer Values

Dividends, divisors, moduli, bases, and exponents all accept positive and negative integers where mathematically valid.

3

Automatic Modular Arithmetic

The calculator applies a custom positive-modulo function and fast modular exponentiation to compute results instantly, even for large exponents.

4

Programming & Mathematics Ready

Each result includes the verification equation and step-by-step working, useful for coursework, debugging, or explaining cryptographic concepts.

Mathematical Formulas

The core equations behind every mode of this calculator.

Remainder = Dividend mod Divisor

The basic modulo operation returns what's left after dividing the dividend by the divisor as many whole times as possible.

Dividend = Divisor × Quotient + Remainder

The division algorithm — this identity is used to verify every Basic Modulo result.

(A + B) mod M, (A − B) mod M, (A × B) mod M

Modular addition, subtraction, and multiplication perform the operation as usual, then reduce the result modulo M.

A^B mod M

Modular exponentiation, computed efficiently with fast exponentiation by squaring rather than computing A^B directly.

Step-by-Step Examples

Six worked examples covering basic modulo, negative numbers, and every modular operation.

Example 1 — Basic Modulo

17 mod 5 ↓ 17 ÷ 5 → Quotient = 3 ↓ Remainder = 2

Example 2 — Negative Dividend

-13 mod 5 ↓ -13 = 5 × (-3) + 2 ↓ Result = 2

Example 3 — Modular Addition

(12 + 9) mod 7 ↓ 21 mod 7 ↓ 0

Example 4 — Modular Subtraction

(18 − 25) mod 6 ↓ -7 mod 6 ↓ 5

Example 5 — Modular Multiplication

(8 × 9) mod 5 ↓ 72 mod 5 ↓ 2

Example 6 — Modular Exponentiation

3⁷ mod 5 ↓ 2187 mod 5 ↓ 2 (computed via fast exponentiation, not direct 2187)

Quick Reference Tables

Common modulo results, modular operation formulas, and real-world applications.

Common Modulo Examples

ExpressionResult
10 mod 31
15 mod 43
18 mod 53
21 mod 70
25 mod 61
30 mod 86

Modular Operations

OperationFormula
Addition(A+B) mod M
Subtraction(A−B) mod M
Multiplication(A×B) mod M
ExponentiationA^B mod M

Real-World Applications

IndustryExample
ProgrammingArray index wrapping
CryptographyRSA encryption
NetworkingHash functions
DatabasesData partitioning
GamingCircular maps
MathematicsNumber theory

Benefits of Using a Modulo Calculator

Why students, programmers, and cryptography professionals reach for a dedicated tool.

Multiple Modular Operations

Addition, subtraction, multiplication, and exponentiation are all supported in one tool.

±

Positive & Negative Support

Correctly applies the mathematical positive-modulo convention for negative dividends.

Fast Modular Exponentiation

Computes A^B mod M efficiently, even for large exponents, without overflow.

🔁

Live Calculations

Results update instantly as you type — no separate submit step required.

📋

Step-by-Step Explanations

Every result includes the working and verification equation, not just the final number.

📱

Mobile-Friendly

Works cleanly on phones and tablets for coursework, debugging, or quick lookups.

Practical Applications

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.

Common Modulo Mistakes

Avoid these to keep every modular calculation and every line of code correct.

Confusing modulo with division

Modulo returns the remainder, not the quotient — 17 mod 5 is 2, not 3.4.

Confusing modulo with percentage

The "%" symbol means modulo in most programming languages, not "percent" — a common beginner mix-up.

Incorrect handling of negative numbers

Some languages return a negative remainder for a negative dividend — always confirm which convention you need.

Using zero as the divisor

Dividing or taking modulo by zero is undefined and will always produce an error.

Forgetting modular reduction

In a multi-step modular calculation, reduce after every operation to avoid unnecessarily large intermediate numbers.

Incorrect exponent calculations

Computing A^B directly before taking mod M can overflow — use fast modular exponentiation instead.

Ignoring modular arithmetic properties

(A+B) mod M is not the same as A mod M plus B mod M unless you reduce the sum again afterward.

Overflow with large numbers

Standard integer types can overflow during multiplication or exponentiation before the modulo is applied — reduce early and often.

Frequently Asked Questions

Common questions about modulo, modular arithmetic, and this calculator.

What is modulo?

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.

What is the difference between modulo and remainder?

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.

How do you calculate modulo?

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.

What happens if the dividend is negative?

This calculator returns the correct positive result — for example, −13 mod 5 = 2 — using the mathematical positive-modulo convention.

Why can't the divisor be zero?

Dividing by zero is undefined in mathematics, so a zero divisor or modulus always produces a validation error instead of a result.

What is modular arithmetic?

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.

What is modular exponentiation?

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.

How is modulo used in programming?

Common uses include wrapping array indices, alternating logic every N iterations, and converting units like seconds into minutes and seconds.

Why is modulo important in cryptography?

Public-key systems like RSA depend on modular exponentiation, which is fast to compute forward but effectively impossible to reverse without a private key.

Can modulo return zero?

Yes — whenever the dividend divides evenly into the divisor, such as 21 mod 7 = 0.

Can modulo return a negative number?

Not with the mathematical positive-modulo convention this calculator uses — results always fall between 0 and one less than the modulus.

Is this calculator accurate?

Yes. It implements a custom positive modulo function and a manually written fast modular exponentiation algorithm, verified against the division algorithm for every result.

Is it free?

Yes, this modulo calculator is free to use with no signup required.

Can I use it on mobile?

Yes, the layout and inputs are designed to work smoothly on phones and tablets.

Who should use this calculator?

Students, programmers, engineers, mathematicians, cybersecurity professionals, and competitive programmers who need fast, verified modular arithmetic results.

Ready to Calculate Modulo Operations Instantly?

Calculate remainders, modular arithmetic, and modular exponentiation with this free professional calculator built for mathematics, programming, engineering, and cryptography.