About the Modulo Calculator tool
The modulo operation gives the remainder after division: 17 mod 5 = 2 because 17 = 5 × 3 + 2. It is used for clock arithmetic, checking whether a number is even, cycling through arrays, hash tables, check digits and cryptography. With positive numbers everyone agrees on the answer, but with a negative number the result depends on the convention — and programming languages disagree.
This modulo calculator shows all three common conventions side by side. Floored modulo, used by Python's % and Excel's MOD, gives a remainder with the sign of the divisor, so −17 mod 5 = 3. Truncated modulo, used by the % operator in C, C++, Java, JavaScript, Go and Rust, gives a remainder with the sign of the dividend, so −17 % 5 = −2. Euclidean modulo, common in number theory, is always between 0 and |n|. The steps write each one as a = n × q + r so you can see where the difference comes from. Decimals and fractions work too, such as 5.5 mod 2 = 1.5.
Two more tabs cover modular arithmetic used in cryptography and competitive programming: power mod computes aᵇ mod m for integers of hundreds of digits by square-and-multiply, and modular inverse finds x with a·x ≡ 1 (mod m) using the extended Euclidean algorithm.
How to use Modulo Calculator
- Choose “a mod n”, “Power mod” or “Modular inverse”.
- For a mod n, enter the dividend a and the divisor n — negative numbers, decimals and fractions are allowed.
- Compare the floored, truncated and Euclidean results to match your language or textbook.
- For power mod, enter the base, exponent and modulus; for the inverse, enter a and m.
- Open “Show steps” to see a = n × q + r, the square-and-multiply sequence or the extended Euclid identity.
Features
Three conventions for negatives
Floored, truncated and Euclidean remainders with the languages that use each.
Works with decimals and fractions
Exact rational arithmetic gives 5.5 mod 2 = 1.5 without floating-point error.
Fast modular exponentiation
Square-and-multiply handles exponents and moduli hundreds of digits long.
Modular inverse
Extended Euclidean algorithm with the Bézout identity and a check line.
When to use it
- Understand why −7 % 3 gives −1 in JavaScript but 2 in Python.
- Work out what time it will be 100 hours from now on a 24-hour clock.
- Compute a modular exponent for an RSA exercise.
- Find a modular inverse for an affine cipher key.
- Check whether a large number is divisible by another.
Frequently asked questions
What does mod mean in maths?
a mod n is the remainder when a is divided by n. 23 mod 7 = 2 because 23 = 7 × 3 + 2.
How do you calculate mod of a negative number?
It depends on the convention. With floored division (Python), −17 mod 5 = 3 because −17 = 5 × (−4) + 3. With truncated division (C, Java, JavaScript), −17 % 5 = −2 because −17 = 5 × (−3) − 2.
Is modulo the same as remainder?
For positive numbers yes. For negative numbers “remainder” often refers to the truncated result, while mathematicians usually mean the non-negative (Euclidean) result when they write a mod n.
What is a modular inverse?
The number x such that a × x leaves remainder 1 when divided by m. The inverse of 3 mod 26 is 9, since 27 = 26 + 1. It only exists when gcd(a, m) = 1.
What happens with mod 0?
It is undefined, because division by zero is undefined. The calculator reports an error.