Modulo Calculator

A modulo calculator takes two numbers and finds the remainder after division. Punch in a dividend and a divisor, hit calculate, and you get the leftover value that doesn't divide evenly. Simple concept, surprisingly useful in a lot of places. Whether you're checking if a number is even, writing a scheduling algorithm, or just brushing up on number theory, the modulo operation shows up constantly. This page walks through how modulo works, how to calculate it by hand, and where it actually matters in the real world.

Enter Details

a mod b

Result

Modulo

Note — This result is an estimate. Talk to a healthcare provider for personalized guidance.

How to Use the Modulo Calculator

Using the calculator is straightforward. You need two values: the dividend (the number being divided) and the divisor (the number you're dividing by). Enter both, then click calculate to see the remainder.

  • Dividend (a): the number you want to divide
  • Divisor (n): the number you're dividing by
  • Result: the remainder left over after division

For example, enter 17 as the dividend and 5 as the divisor. The calculator returns 2, because 17 divided by 5 equals 3 with a remainder of 2. You can also use decimal inputs depending on what the tool supports, but modulo is most commonly applied to integers.

What Is the Modulo Operation?

The modulo operation finds the remainder when one integer is divided by another. If you divide 10 by 3, you get 3 with 1 left over. That leftover, 1, is the result of 10 mod 3.

It's different from regular division because you're not interested in the quotient. You only care about what's left behind after as many whole divisions as possible have been taken out. Think of it like cutting a rope into equal pieces and measuring the scrap at the end.

The notation varies depending on context. In math, you'll often see it written as a mod n. In most programming languages, the percent sign is used instead: a % n. Both mean the same thing: divide a by n and give me the remainder.

Modulo Formula

The formula for modulo comes directly from the division algorithm. Given integers a (dividend) and n (divisor, where n ≠ 0), the remainder r is defined as:

a = n × q + r

Where q is the quotient (the whole number result of division) and r is the remainder such that 0 ≤ r < n for positive values. So to find r manually: divide a by n, take the floor of that result to get q, then multiply q by n and subtract from a.

For example, with a = 23 and n = 7: 23 ÷ 7 ≈ 3.28, so q = 3. Then r = 23 − (7 × 3) = 23 − 21 = 2. That means 23 mod 7 = 2.

Modulus vs Remainder

People use these words interchangeably all the time, but they're not always the same thing. The remainder is the raw leftover from division and can be negative depending on how the division is handled. The modulus in formal mathematics is always non-negative.

Where this matters most is with negative numbers. In strict mathematical modulo, the result is always between 0 and n−1. But in programming, many languages return a remainder that keeps the sign of the dividend. So −7 mod 3 gives 2 in math (since −7 = 3 × (−3) + 2), but some languages return −1 instead.

If you're working in a math context, expect non-negative results. If you're coding, check your language's behavior with negative inputs.

Understanding the Mod Operator (%)

In programming, the percent sign % is the modulo (or remainder) operator. It works on integers in most languages and behaves like you'd expect for positive numbers: 17 % 5 returns 2.

The tricky part is how different languages handle negatives. Here's a quick comparison:

LanguageExpressionResult
Python-7 % 32
JavaScript-7 % 3-1
Java-7 % 3-1
Ruby-7 % 32

Python and Ruby follow the mathematical convention, keeping the result positive. JavaScript and Java return a result that matches the sign of the dividend. When portability matters, it's worth knowing which behavior you're relying on.

Modular Arithmetic Calculator

Modular arithmetic is a system where numbers wrap around after reaching a certain value, called the modulus. Think of a clock: after 12, you go back to 1, not 13. That wrapping behavior is exactly what modular arithmetic describes.

A modular arithmetic calculator lets you perform addition, subtraction, multiplication, and sometimes exponentiation under a given modulus. Instead of computing a raw result, you compute the result and then reduce it using mod. It's used heavily in cryptography, computer science, and number theory.

The notation a ≡ b (mod n) means that a and b leave the same remainder when divided by n. They're said to be congruent modulo n.

Basic Modular Arithmetic Rules

A few rules make modular arithmetic predictable and easy to work with:

  • Any multiple of n is congruent to 0 (mod n). So 12 mod 4 = 0.
  • You can reduce before or after operations. (a + b) mod n = ((a mod n) + (b mod n)) mod n. This is useful when numbers get large.
  • The result is always between 0 and n−1 in standard mathematical modulo.
  • Modulo distributes over addition and multiplication but not division. Division requires modular inverses, which is a different topic.

These properties are what make modular arithmetic so powerful in proofs and algorithms. You can simplify massive numbers down to small remainders and still get correct results.

Addition, Subtraction, and Multiplication Modulo

Each basic operation has a clean rule in modular arithmetic.

Addition: (a + b) mod n. Compute a + b normally, then take mod. Or reduce each term first: ((a mod n) + (b mod n)) mod n. Example: (14 + 9) mod 5 = 23 mod 5 = 3.

Subtraction: (a − b) mod n. Same idea. If the result goes negative, add n to bring it back into range. Example: (3 − 7) mod 5 = −4 mod 5 = 1 (since −4 + 5 = 1).

Multiplication: (a × b) mod n. Again, you can reduce before or after. Example: (6 × 7) mod 4 = 42 mod 4 = 2. Or: (6 mod 4) × (7 mod 4) mod 4 = 2 × 3 mod 4 = 6 mod 4 = 2. Same answer either way.

This flexibility is extremely useful when dealing with large numbers, since you can keep values small throughout a calculation rather than letting them balloon.

Modulo Calculator with Steps

Doing modulo by hand isn't complicated once you have a clear process. Here are the steps:

  1. Identify a and n. Know your dividend and divisor.
  2. Divide a by n. Get the decimal result.
  3. Take the floor. Round down to the nearest whole number. This is your quotient q.
  4. Multiply q by n. Find q × n.
  5. Subtract from a. r = a − (q × n). That's your remainder.

Let's walk through a full example: 58 mod 9.

  1. a = 58, n = 9
  2. 58 ÷ 9 = 6.444...
  3. Floor(6.444) = 6, so q = 6
  4. 6 × 9 = 54
  5. 58 − 54 = 4

Result: 58 mod 9 = 4. You can verify: 9 × 6 = 54, and 54 + 4 = 58. Checks out.

Finding the Remainder Using Modulo

Finding a remainder is the entire point of the modulo operation. It tells you what's left after dividing as evenly as possible. This is useful in a surprising number of everyday situations: splitting things into equal groups, checking divisibility, cycling through arrays in code, and more.

The key is understanding what the remainder actually represents. If you have 29 items and want to split them into groups of 6, the modulo tells you how many items don't fit into a complete group. 29 mod 6 = 5, so 5 items are left over after forming 4 complete groups of 6.

Positive Number Examples

Positive numbers are the straightforward case. Here are a few examples to illustrate:

  • 20 mod 6 = 2 (20 = 6 × 3 + 2)
  • 45 mod 7 = 3 (45 = 7 × 6 + 3)
  • 100 mod 10 = 0 (100 divides evenly, no remainder)
  • 13 mod 13 = 0 (any number mod itself equals 0)
  • 7 mod 15 = 7 (when the dividend is smaller than the divisor, the remainder is just the dividend)

That last one trips people up. If a < n, then a mod n = a, because 0 whole divisions fit, and the entire value is the remainder.

Negative Number Examples

Negative numbers make modulo a little more interesting. Math and programming languages don't always agree here, so let's look at both perspectives.

Using the mathematical convention (result is always non-negative):

  • −10 mod 3: q = floor(−10 / 3) = floor(−3.33) = −4. r = −10 − (3 × −4) = −10 + 12 = 2
  • −7 mod 5: q = floor(−7 / 5) = floor(−1.4) = −2. r = −7 − (5 × −2) = −7 + 10 = 3

Using the truncation-toward-zero convention (common in C, Java, JavaScript):

  • −10 % 3 = −1
  • −7 % 5 = −2

The difference is in how the quotient is rounded. Math uses the floor (always rounds toward negative infinity), while many programming languages truncate toward zero. Know which convention applies to your situation before relying on the result.

Congruence and Modular Equations

Congruence is the formal language of modular arithmetic. Two numbers are congruent modulo n if they have the same remainder when divided by n. This idea is foundational in number theory and has real practical implications in areas like cryptography and hashing.

Modular equations take this further by asking: given a relationship between numbers under a modulus, what values satisfy it? These equations look different from regular algebra, but many of the same instincts apply once you understand the rules of the system.

Modular Congruence Explained

The notation a ≡ b (mod n) is read as "a is congruent to b modulo n." It means that n divides the difference a − b evenly. In other words, (a − b) mod n = 0.

Some examples:

  • 17 ≡ 2 (mod 5) because 17 − 2 = 15, and 15 is divisible by 5.
  • 26 ≡ 2 (mod 8) because 26 − 2 = 24, and 24 ÷ 8 = 3 exactly.
  • 100 ≡ 0 (mod 10) because 100 is divisible by 10.

Congruence is an equivalence relation, which means it's reflexive (a ≡ a), symmetric (if a ≡ b then b ≡ a), and transitive (if a ≡ b and b ≡ c then a ≡ c). These properties make it behave a lot like equality, but within a modular system.

Solving Simple Congruence Problems

A simple congruence equation looks like this: x ≡ a (mod n). The solution isn't a single number but a whole family of numbers. Any x of the form x = a + k×n (for any integer k) satisfies the equation.

Example: Solve x ≡ 3 (mod 7). Solutions include 3, 10, 17, 24, and also −4, −11, etc. All of them leave a remainder of 3 when divided by 7.

Slightly harder: solve 2x ≡ 4 (mod 6). Divide both sides by 2... but you can only do that if 2 and 6 share certain properties. Here, dividing gives x ≡ 2 (mod 3), so x = 2, 5, 8, 11, and so on. When coefficients and the modulus share a common factor, the solution set changes, so you need to check divisibility of the common factor into the right-hand side before dividing.

Modulo Calculation Examples

A handful of worked examples shows just how flexible modulo is across different number types and scenarios.

ExpressionCalculationResult
25 mod 425 = 4 × 6 + 11
100 mod 7100 = 7 × 14 + 22
81 mod 981 = 9 × 9 + 00
50 mod 1150 = 11 × 4 + 66
7 mod 207 = 20 × 0 + 77
−13 mod 5 (math)−13 = 5 × (−3) + 22

Notice the row where the dividend is smaller than the divisor (7 mod 20). The quotient is 0 and the full dividend becomes the remainder. And the negative example follows the floor-division convention, giving a positive result as expected in standard mathematical modulo.

Applications of Modulo in Programming

Modulo is everywhere in software development. Once you start looking for it, you'll find it in almost every non-trivial codebase.

  • Even/odd check: If n % 2 == 0, the number is even. That's probably the most common use of modulo in code.
  • Cycling through arrays: Use index % array.length to wrap around to the start when you reach the end. Useful for carousels, round-robin scheduling, and ring buffers.
  • Hash tables: Hash functions often use modulo to map a computed hash value into a fixed-size array: hash(key) % tableSize.
  • Clock arithmetic in time: Converting seconds to hours, minutes, and seconds requires modulo. 3661 seconds: 3661 % 60 = 1 second, then floor(3661 / 60) % 60 = 1 minute, and so on.
  • Cryptography: RSA and other public-key systems rely heavily on modular exponentiation. Without modulo, modern encryption wouldn't work.
  • Checksums and parity bits: Error-detection schemes use modular arithmetic to verify data integrity.

It's one of those operators that looks simple but punches well above its weight in terms of how much real-world work it does.

Applications of Modular Arithmetic in Mathematics

In pure math, modular arithmetic is a core tool in number theory and abstract algebra. It's not just a curiosity; it's foundational to some of the most important results in mathematics.

Divisibility tests are based on modular arithmetic. The rule that a number is divisible by 9 if its digits sum to a multiple of 9 comes directly from the fact that 10 ≡ 1 (mod 9), so each digit's place value reduces to 1 under that modulus.

Fermat's Little Theorem states that if p is prime and a is not divisible by p, then a^(p−1) ≡ 1 (mod p). This result is used in primality testing and is a building block for RSA encryption.

The Chinese Remainder Theorem lets you solve systems of simultaneous congruences under different moduli, provided those moduli are coprime. It's a powerful result with applications in signal processing and computer arithmetic.

Modular arithmetic also appears in group theory. The integers mod n under addition form a cyclic group, written Z/nZ. These structures are studied in abstract algebra and connect modular arithmetic to much broader mathematical frameworks.

Beyond the theory, modular arithmetic shows up in calendar calculations (figuring out what day of the week a date falls on), music theory (the 12-tone scale wraps around in a way that's naturally modular), and competitive math problems where large numbers need to be simplified quickly. It's a genuinely versatile concept that rewards getting comfortable with.

Other Maths Calculators

Explore all