Skip to content
Math & Scientific

Mod Calculator

Mod Calculator

Explore modular arithmetic: reduce a number modulo n, or check whether two numbers are congruent.

Fill b to test congruence a ≡ b (mod n).

A positive whole number.

The result always lies in 0 ≤ r < n. Two numbers are congruent mod n when n divides their difference.

Clock arithmetic is something you already do. When it is 10 o'clock and someone says "see you in 5 hours," you answer 3 o'clock, not 15 o'clock. You wrapped around the 12 without thinking, and that wrap-around is exactly what modular arithmetic studies.

The calculator above makes the wrap-around explicit. Enter a number and a modulus, and it reduces the number to its residue, the remainder left after removing every full copy of the modulus. Optionally add a second number to test whether the two are congruent.

This guide explains residues, congruence, and the sign rules that make negative numbers behave, so the results always make sense.

What Does the Mod Calculator Do?

You enter a number a and a modulus n. The calculator returns a mod n: the value in the range 0 to n − 1 that differs from a by a whole multiple of n.

The second line shows the decomposition, a written as n times a quotient plus the residue. For 17 mod 12, you see 17 = 12 × 1 + 5, which is the calculator showing its work.

Fill in the optional b field and the calculator also reduces b, then tells you whether a and b are congruent modulo n. That verdict is the heart of modular arithmetic.

How to Use the Mod Calculator

Type your number into the "Number a" box. Decimals are accepted, though most modular arithmetic uses whole numbers.

Type a positive whole number into the "Modulus n" box. The calculator rejects zero, negatives, and fractions here, because the modulus defines the size of the wrap-around.

Press Calculate. The residue appears in the headline with the decomposition below. Add a value to "Number b" and press Calculate again to get the congruence verdict too. Press Reset to start over.

What "Mod n" Actually Means

Saying "a mod n" asks: if I remove as many full copies of n from a as possible, what is left? For 17 mod 12, one full 12 comes out, leaving 5.

The removed copies are counted by the quotient, which is the floor of a divided by n. The leftover is the residue, always a non-negative number smaller than n.

This is why 17 mod 12 is 5 and also why 29 mod 12 is 5: both numbers sit 5 past a multiple of 12. The modulus erases the difference between them.

Another way to see it is repeated subtraction. Subtract 12 from 17 once and you reach 5, which is smaller than 12, so you stop. Whatever remains when you can no longer subtract n is the residue, and the count of subtractions is the quotient.

Residues: Why the Answer Always Falls Between 0 and n − 1

There are exactly n possible residues mod n: 0, 1, 2, up to n − 1. Every integer on the number line lands on exactly one of them, which is why modular arithmetic is sometimes called clock arithmetic.

The calculator enforces this range even for negative inputs. Negative seventeen mod 5 is 3, not −2, because the residue must sit in the 0-to-4 window.

This convention, always landing in 0 to n − 1, is the mathematical standard. Programming languages sometimes disagree on negatives, which is exactly the confusion the next sections clear up.

Think of the residues as labeled slots. No matter how large or how negative your input is, it drops into exactly one slot, and two numbers in the same slot are interchangeable for every modular calculation that follows.

Congruence: When Two Numbers Are the Same Mod n

Two numbers are congruent modulo n, written a ≡ b (mod n), when they leave the same residue. Equivalently, n divides their difference with nothing left over.

Seventeen and 5 are congruent mod 12 because both reduce to 5, and 17 − 5 = 12, which 12 divides evenly. Congruence is the precise way of saying "these behave identically on the clock."

The calculator's verdict line states this directly. When the residues match, you get the congruence; when they differ, you see both residues so you can spot where the numbers diverge.

Worked Example: 17 mod 12

You want the residue of 17 modulo 12.

First: enter 17 as a and 12 as n, then press Calculate.

The calculator removes one full 12 from 17, leaving 5.

The headline reads: 17 mod 12 = 5.

The decomposition reads: 17 = 12 × 1 + 5.

Answer: 5.

Worked Example: −17 mod 5

You want the residue of −17 modulo 5.

First: enter −17 as a and 5 as n, then press Calculate.

The calculator finds the multiple of 5 just below −17, which is −20, and the leftover is 3.

The headline reads: −17 mod 5 = 3.

The decomposition reads: −17 = 5 × −4 + 3.

Answer: 3, always non-negative, as the residue rule requires.

Worked Example: Are 17 and 5 Congruent mod 12?

You want to test whether 17 ≡ 5 (mod 12).

First: enter 17 as a, 5 as b, and 12 as n, then press Calculate.

The calculator reduces 17 to 5 and reduces 5 to 5.

The verdict reads: Congruent: 17 ≡ 5 (mod 12) since both reduce to 5.

Answer: yes, they are congruent.

Worked Example: 17 and 6 Are Not Congruent mod 12

You want to test whether 17 ≡ 6 (mod 12).

First: enter 17 as a, 6 as b, and 12 as n, then press Calculate.

The calculator reduces 17 to 5 but 6 stays 6.

The verdict reads: Not congruent: 17 reduces to 5 but 6 reduces to 6.

Answer: no. Their difference is 11, which 12 does not divide.

Negative Numbers and Mod

Negatives are where most people stumble. The residue of −17 mod 5 is 3, because you go down to the next multiple of 5 (−20) and measure the gap upward.

Some calculators and programming languages return −2 for −17 mod 5 instead. That is the truncated remainder, a different convention that keeps the sign of the dividend.

The Mod Calculator always uses the mathematical convention: the residue lands in 0 to n − 1. If you need the truncated remainder behavior, the companion Modulo Calculator shows both conventions side by side.

Why n Must Be a Positive Whole Number

The modulus defines how many distinct residues exist, and "how many" has to be a positive count. A modulus of zero would mean dividing by nothing, and a negative modulus would flip the residue window upside down.

Fractional moduli are rejected for a similar reason: the wrap-around only makes clean sense when n counts whole steps. The calculator validates this and asks for a positive whole number if you slip.

The number a, by contrast, can be anything, including decimals and negatives. Only the modulus carries the restriction.

Common Mod Mistakes

The most common mistake is reading the quotient as the answer. The quotient counts how many full copies of n were removed; the residue, the leftover, is the result of the mod operation.

The second is assuming mod keeps the sign of the input. It does not, under the mathematical convention. Negative inputs still produce non-negative residues, which surprises anyone coming from a programming background.

The third is testing congruence by comparing the numbers directly instead of their residues. Seventeen and 29 look nothing alike, but both reduce to 5 mod 12, so they are congruent.

Where Modular Arithmetic Is Useful

Clocks and calendars are the everyday face of mod arithmetic: hours wrap mod 12, weekdays wrap mod 7. Scheduling problems that "wrap around" are mod problems in disguise.

Computer science uses it everywhere: hash tables place items with mod, random number generators cycle with mod, and checksums validate data with mod. Cryptography, including RSA, is built on modular exponentiation.

Even music theory leans on it. The twelve pitch classes wrap mod 12 exactly like a clock, which is why the same interval pattern repeats in every octave.

Puzzles and games use it too. Card shuffles, tournament brackets, and seating rotations all ask "where do we land after wrapping around," and the modulus is the quiet tool answering every time.

How to Interpret Your Result Correctly

Read the headline as "where a lands on the n-clock." It is always one of n possible positions, which makes it a classification as much as a calculation.

Read the decomposition as the proof. It shows the quotient and residue recombining into the original number, so you can verify the arithmetic without trusting the tool blindly.

Read the verdict as a yes-or-no about sameness. Congruence does not mean the numbers are equal; it means they are indistinguishable to anyone who only watches the clock.

When a result surprises you, rerun it with the decomposition in mind. Write out the multiples of n near your input by hand, and the residue the calculator reports will match the gap you measure yourself.

Frequently Asked Questions

1. What is 17 mod 12?

It is 5. One full 12 comes out of 17, leaving 5, so 17 = 12 × 1 + 5. Enter 17 and 12 in the calculator to see the residue and the decomposition.

2. What does "a is congruent to b mod n" mean?

It means a and b leave the same residue when divided by n, or equivalently that n divides their difference. Seventeen and 5 are congruent mod 12 because both reduce to 5.

3. Why is −17 mod 5 equal to 3 and not −2?

The calculator uses the mathematical convention, where the residue always lies between 0 and n − 1. The multiple of 5 just below −17 is −20, and the gap up to −17 is 3. The −2 answer comes from a different, truncated convention.

4. Can the modulus be zero or negative?

No. A zero modulus would mean division by zero, and a negative modulus breaks the residue window. The calculator requires n to be a positive whole number and says so if you enter anything else.

5. Can I use decimals with the Mod Calculator?

You can enter decimals for a and b, and the calculator will reduce them. Classical modular arithmetic uses integers, though, so whole numbers give the cleanest and most meaningful results.

6. What is the difference between mod and remainder?

For positive numbers there is none. They diverge on negatives: mathematical mod always returns a non-negative residue, while a truncated remainder keeps the dividend's sign. The Modulo Calculator shows both conventions so you can compare.

7. How do I check if two numbers are congruent?

Enter both numbers and the modulus, and the calculator reduces each one. If the residues match, the numbers are congruent; the verdict line states it plainly with both residues shown.

8. What is a residue class?

It is the set of all integers that share the same residue mod n. The residue class of 5 mod 12 contains 5, 17, 29, −7, and infinitely many more, all behaving identically on the 12-clock.

9. Why does the calculator show a decomposition line?

It proves the answer. Writing a as n × quotient + residue lets you verify that the pieces recombine into the original number, which catches entry mistakes immediately.

10. Is 0 mod n always 0?

Yes. Zero contains zero full copies of n with nothing left over, so the residue is 0 for any positive n. It is also congruent to every multiple of n.

11. What happens if a is smaller than n?

Then no full copies of n come out, the quotient is 0, and the residue is a itself. For example, 5 mod 12 is simply 5.

12. Where is modular arithmetic used in real life?

Clocks, calendars, hash tables, checksums, random number generators, and public-key cryptography all rely on it. Any system that wraps around after reaching a limit is doing modular arithmetic.

13. What does the ≡ symbol mean?

It denotes congruence. Writing a ≡ b (mod n) asserts that a and b leave the same remainder on division by n, which is weaker than equality but exactly right for wrap-around systems.

14. Can the modulus be 1?

Yes, and everything becomes 0 mod 1, because 1 divides every integer. It is a valid but uninteresting modulus, since there is only one residue class.

15. How is this different from the Modulo Calculator?

This tool explores modular arithmetic: residues and congruence under the mathematical convention. The Modulo Calculator decomposes a division into quotient and remainder and compares the truncated and floored sign rules, which is a different question.