Skip to content
Other

Modulo Operator Calculator

Enter a dividend and a divisor to find the remainder of the division - the result of the modulo operation. Choose from three common remainder conventions (Euclidean, truncated, and floor), explore six practical use-case modes, and follow the step-by-step working to see exactly how the answer is reached.

Your details

Each mode pre-fills sensible defaults and shows the relevant practical interpretation.
Conventions differ for negative inputs. For positive numbers all three agree. Euclidean is the most mathematically standard.
The number being divided.
The number dividing the dividend. Cannot be zero.
Remainder (a mod n)Remainder: 2
2

The remainder after dividing the dividend by the divisor.

Quotient3
Verification3 x 5 + 2 = 17
Interpretation17 divided by 5 leaves a remainder of 2.
Remainder2
Quotient3
02401020
Dividend (a), divisor = 5
Remainder (a mod n)
Dividend (a), divisor = 5a mod 5
00
11
22
33
44
50
61
72
83
94
100
111
122
133
144
150
161
172
183
194
200

17 mod 5 = 2

  • The remainder 2 satisfies a = q x n + r, so 17 = 3 x 5 + 2.
  • Because the remainder is non-zero, 5 does not divide 17 exactly.
  • The remainder is always between 0 (inclusive) and |n| (exclusive) for Euclidean convention.

Next stepTry the Divisibility check or Odd/Even mode for a targeted practical use case.

Formula

amod  n=a−n⋅⌊an⌋(Euclidean: r≥0)a \mod n = a - n \cdot \left\lfloor \dfrac{a}{n} \right\rfloor \quad (\text{Euclidean: } r \ge 0)

Worked example

17 mod 5: divide 17 by 5 to get quotient 3 (since 3 x 5 = 15). Remainder = 17 - 15 = 2. Verify: 3 x 5 + 2 = 17. So 17 mod 5 = 2. Clock example: 27 mod 12 = 3, so 27 hours after noon the clock reads 3:00.

What is the modulo operator?

The modulo operator (written mod, %, or rem depending on the language or convention) returns the remainder left over after integer division. If you divide a by n, you get a quotient q and a remainder r such that a = q x n + r. The modulo operation isolates that r. For example, 17 mod 5 = 2 because 17 = 3 x 5 + 2. When the remainder is zero, the dividend is exactly divisible by the divisor - a zero result is the universal divisibility test.

Why does the remainder convention matter for negative numbers?

For positive inputs all three common conventions (Euclidean, truncated, and floor/Python-style) give the same answer. They differ when the dividend or divisor is negative. The truncated convention (used in C, JavaScript, Java, and most languages) lets the remainder carry the sign of the dividend: -7 mod 3 = -1. The floor convention (Python, Ruby) makes the remainder carry the sign of the divisor: -7 mod 3 = 2. The Euclidean convention always returns a non-negative remainder: -7 mod 3 = 2. For most practical use cases - clock arithmetic, cyclic indices, divisibility tests - Euclidean or floor convention is preferred because negative remainders can cause off-by-one errors in array indexing.

Six practical uses covered by this calculator

Basic remainder: the fundamental operation - enter any dividend and divisor, choose a convention, and see the quotient, remainder, and step-by-step working. Odd/even detection: x mod 2 is either 0 (even) or 1 (odd) - the fastest parity check in any language. Clock arithmetic: hours mod 12 wraps a running hour count back onto the 12 positions of a clock face; the same idea applies to days mod 7 for weekdays, or months mod 12 for calendar cycles. Unit conversion: dividing total minutes by 60 gives whole hours, and the modulo gives the leftover minutes - an everyday use case whenever you express a quantity in two units (hours and minutes, feet and inches, degrees and minutes of arc). Divisibility check: if a mod n = 0, n is a factor of a. Congruence: two numbers are congruent mod n if they leave the same remainder - the language behind RSA encryption, Chinese Remainder Theorem, and cyclic scheduling.

Modular arithmetic in cryptography and computing

Modern public-key cryptography, including RSA and Diffie-Hellman key exchange, relies on modular exponentiation: computing a^e mod n for very large numbers. The security comes from the fact that computing the result is fast while reversing it (the discrete-logarithm problem) is computationally infeasible. Hash tables use index = hashCode mod tableSize to map an arbitrary hash value to a valid array position. Pseudo-random number generators use a linear congruential formula: x_next = (a x x_current + c) mod m. Cyclic redundancy checks (CRC codes) for error detection in networking are based on polynomial modulo arithmetic. The simple remainder operation appears at almost every layer of computer science.

Common practical uses of the modulo operator

Use caseExpressionWhat it tells you
Odd / Even checka mod 20 = even, 1 = odd
12-hour clockhours mod 12Current hour hand position (12 instead of 0)
Day of the weekdays mod 70 = Sunday ... 6 = Saturday (or chosen epoch)
Minutes to h:mintotal mod 60Leftover minutes after extracting whole hours
Divisibility testa mod n = 0?True means n is a factor of a
Array wrap-aroundindex mod lengthCycles index back to 0 at end of array
Congruence check(a - b) mod n = 0?True means a and b are in the same residue class
Leap year (Gregorian)year mod 4, 100, 400Divisible by 4 and not 100 (or divisible by 400)
RSA encryptionm^e mod nCore of public-key cryptographic operations
Hash function buckethash mod tableSizeMaps hash codes to array indices

A quick reference for the most common real-world applications of modular arithmetic.

Frequently asked questions

What is the difference between modulo and remainder?

For positive numbers they are identical. The difference shows up for negative inputs. In mathematics, the Euclidean remainder is always non-negative (between 0 and |n| - 1). Many programming languages (C, JavaScript, Java) define % as a truncated remainder that can be negative. Python and Ruby use a floor-based remainder that matches the Euclidean result when the divisor is positive. This calculator lets you pick the convention explicitly.

Why does 27 mod 12 = 3 on the clock example?

27 divided by 12 gives quotient 2 (two full 12-hour cycles) and remainder 3 (hours left over). So after 27 hours the clock hand is at position 3. If the remainder were 0 the display shows 12 rather than 0, because a 12-hour clock has no zero position - the calculator handles this automatically.

How do I check if a number is even or odd with modulo?

Divide by 2 and look at the remainder. If the remainder is 0 the number is even; if it is 1 the number is odd. This works for any integer, positive or negative. In most programming languages the expression is (n % 2 === 0) for even and (n % 2 !== 0) for odd.

What does "congruent mod n" mean?

Two integers a and b are congruent modulo n (written a ≡ b mod n) if their difference (a - b) is divisible by n, which is the same as saying they leave the same remainder when divided by n. For example, 38 ≡ 14 (mod 12) because both leave remainder 2 and their difference 24 is divisible by 12. This is the language used in number theory and cryptography to describe numbers that are "equivalent" under a cyclic system.

Why is the modulo result always less than the divisor?

By definition, the remainder r must satisfy 0 <= r < |n| (for Euclidean convention). If r were as large as n, you could subtract another n from the dividend and the quotient would increase by 1, so r would not actually be the remainder. A remainder of 0 means the division was exact; a remainder of n - 1 is the maximum possible.

How is modulo used in unit conversion?

When you want to express a total in two units (total minutes into hours and minutes), you use integer division for the larger unit (floor(total / 60) = whole hours) and modulo for the smaller unit (total mod 60 = leftover minutes). The same pattern converts total seconds into hours:minutes:seconds, total inches into feet and inches, or total arc-seconds into degrees, minutes, and seconds.

Sources

Written by Grace Mbeki, MSc Data Scientist & Educator · Nairobi, Kenya

Turning everyday numbers into clear, actionable answers for the decisions that matter most.

Search 3,500+ calculators

Loading search…