Modulo Calculator
Choose what you want: a mod n, a power modulo m, or a modular inverse. Large whole numbers are fine, and negative numbers show the different conventions.
Whole numbers only.
Worked examples
A simple remainder
17 mod 5
2
17 = 5 × 3 + 2.
A power modulo
4 to the power of 13 mod 497
445
Worked by repeated squaring.
About Modulo Calculator
The modulo operation gives the remainder when one whole number is divided by another. 17 mod 5 is 2, because 5 goes into 17 three times with 2 left over. It is the arithmetic of clocks: 15 hours after 10 o'clock is 1 o'clock because 25 mod 12 is 1. It is used in check digits on bank and barcode numbers, to cycle through lists and days of the week, and in cryptography.
Negative numbers are where tools disagree. For -7 mod 3, the truncated remainder is -1, which is what many programming languages return, but the floored result used in mathematics is 2. The page shows both. It also finds a power modulo a number without ever writing out the huge power, using repeated squaring, so 4 to the power of 13 mod 497 comes to 445 at once. The third option gives the modular inverse, the number which times a gives 1 mod m, if one exists. All of it is exact for whole numbers of up to 40 digits.
How to use Modulo Calculator
- Choose a mod n, a power modulo m, or a modular inverse.
- Enter a, and then n or the power and modulus, in the boxes that appear.
- Read the result, and for a mod n the truncated and floored remainders.
- Check the working line to confirm the answer.
Common uses
- Checking remainders and divisibility
- Clock and calendar arithmetic
- Computer science and cryptography exercises
- Check digit calculations
Frequently asked questions
What is 17 mod 5?
It is 2. 5 × 3 = 15, and 17 - 15 = 2.
Why do negative numbers give different answers?
There are two conventions. The truncated remainder takes the sign of the dividend, while the floored remainder takes the sign of the divisor. In mathematics the second is standard, so -7 mod 3 is 2.
What is a modular inverse?
It is the number b where a × b leaves a remainder of 1 when divided by m. It exists only when a and m share no common factor.
How can a huge power be found modulo m?
By squaring and taking the remainder at each step, so the numbers never get large. This page does that automatically.
Can I use decimals?
No. The modulo operations on this page are for whole numbers only.