Utinzo

Modulo Calculator

Calculate the remainder of division (modulo operation). Supports positive and negative numbers and shows the full division breakdown.

Did this tool work for you?

How to use this calculator

a mod m = a − m × floor(a/m)

The modulo operation returns the remainder when a is divided by m.

  1. 1

    Enter the dividend (number being divided).

  2. 2

    Enter the modulus (divisor).

  3. 3

    The result is the remainder after floor division.

  4. 4

    Note: for negative numbers, mathematical modulo differs from the % operator in most languages.

Frequently asked questions

Why does -17 mod 5 give 3 here but -2 in my programming language?

This calculator uses floored division, so the remainder takes the sign of the modulus and always lands between 0 and m. -17 = 5 × (-4) + 3, hence 3. The % operator in JavaScript, Java, C and many other languages truncates toward zero and keeps the sign of the dividend, giving -2. The fourth result row shows the % value and flags when it differs. Python’s % matches the floored result.

What does a negative modulus do?

The remainder becomes zero or negative, between m and 0. For 17 mod -5 the quotient is floor(17 ÷ -5) = -4 and the remainder is -3, since -5 × -4 + -3 = 17. The remainder is never positive. Most people use positive moduli, where the answer is always 0 to m − 1.

Can the modulus be zero?

No. Division by zero is undefined, so the calculator returns “Modulus cannot be zero”. Blank or non-numeric fields return a prompt to enter numbers in both fields.

Does it work with decimals?

Yes. 5.5 mod 2 is 1.5 and -7.5 mod 2 is 0.5. Because decimals like 0.1 cannot be stored exactly in binary, the tool trims floating-point noise before flooring, so 0.3 mod 0.1 returns 0 as you would expect. The JS % row still shows 0.1 for that case, which is a good illustration of the rounding trap in raw code.

What does it mean when the answer is 0?

The first number is an exact multiple of the second. 2100 mod 100 is 0 because 2100 = 100 × 21. Use that to test divisibility: n mod 2 = 0 means even, and n mod 3 = 0 means divisible by 3.

What if the dividend is smaller than the modulus?

The quotient is 0 and the remainder equals the dividend, so 3 mod 7 = 3. A negative dividend smaller in size than the modulus wraps around: -1 mod 7 = 6.

How big can the numbers be?

The tool uses ordinary double-precision numbers. Integers are exact up to 9,007,199,254,740,991 (2⁵³ − 1); beyond that, digits can be lost and the remainder may be wrong. For cryptographic-size integers use a big-integer tool.

Does it compute modular inverses or powers?

No. It evaluates a single remainder a mod m. It does not find inverses, solve congruences, or compute large exponents such as aᵇ mod m.

About modulo calculator

Modulo calculator — remainders, negatives and clock arithmetic

Definition used by this calculator

The remainder is a mod m = a − m × floor(a ÷ m). The floor rounds the quotient down, which matters whenever a is negative. For a positive modulus the result is always at least 0 and less than m, so the values wrap around like a clock face. The output shows the remainder, the floored quotient, a check line that multiplies back (m × quotient + remainder = a), and what the % operator would give.

Worked examples

Floored modulo versus the % operator. The columns show a mod m, Floored result, Quotient and % operator, one line per case.

Floored modulo versus the % operator
a mod mFloored resultQuotient% operator
17 mod 5232
-17 mod 53-4-2
17 mod -5-3-42
-1 mod 76-1-1
-7.5 mod 20.5-4-1.5
109 mod 12191

Clocks, calendars and weekdays

Anything that repeats in a cycle is modular arithmetic. Nine o’clock plus 100 hours: 109 mod 12 = 1, so the clock reads 1 on a 12-hour face. Forty-five days after a Tuesday: 45 mod 7 = 3, so count three weekdays ahead and land on Friday. Going backwards works too: if weekdays are numbered 0 to 6, the day before day 0 is -1 mod 7 = 6, the last slot.

Divisibility and leap years

A remainder of zero means exact divisibility. The Gregorian leap-year rule is a chain of such tests: divisible by 4, except centuries, except centuries divisible by 400. Running 2100 against each modulus gives 2100 mod 4 = 0, 2100 mod 100 = 0 and 2100 mod 400 = 100, so 2100 is divisible by 4 and by 100 but not by 400, which makes it a common year.

Hashing, indexing and checks

Programs use modulo to wrap an index into an array of fixed size, to spread keys across buckets, and to compute check digits. For instance 123456789 mod 97 = 39, a quick way to map a large ID to one of 97 buckets. If the value can be negative, check which version of modulo your language uses, because the % operator can return a negative index that the floored version here would never produce.

Modulo Calculator – Utinzo

Learn more from an authoritative source:

Wikipedia
Related tools

Results are estimates for informational purposes only and do not constitute professional financial, medical, legal, or technical advice. Read full disclaimer →