Modulo Calculator
Beta: this tool hasn't been fully reviewed yet. Double-check results before relying on them.
Inputs
Fill in to compute aᵉ mod n, even for exponents with dozens of digits.
Whole numbers up to 60 digits; a and e can be negative or zero, n must be positive.
Results
Enter whole numbers, with a modulus n greater than 0 and an exponent of 0 or more.
- a mod n
- —
- aᵉ mod n
- —
- Division
- —
- Remainder as in C, Java, JavaScript (a % n)
- —
- Modular inverse of a
- —
Extended Euclidean algorithm
| a | b | Quotient | Remainder |
|---|
Your input is too long to share as a link, so the page address no longer includes it.
The modulo operation gives the remainder after division: 17 mod 5 = 2, because 17 = 5 × 3 + 2. It’s how clocks wrap around, how check digits are computed, and the heart of cryptography such as RSA. This calculator works with whole numbers of any size, exactly.
How to use it
- Enter the number a and the modulus n.
- Optionally enter an exponent e to compute aᵉ mod n.
- Read the result, the division it comes from, the modular inverse and the Euclidean algorithm steps.
Examples: 17 mod 5 = 2. −7 mod 3 = 2 in math, but −7 % 3 = −1 in C, Java and JavaScript. 3²⁰⁰ mod 13 = 9. The inverse of 3 mod 11 is 4, since 3 × 4 = 12 = 11 + 1. 4 has no inverse mod 8, because they share the factor 4.
Questions and answers
Why do −7 mod 3 and −7 % 3 differ?
Mathematicians choose the remainder between 0 and n − 1, so −7 = 3 × (−3) + 2 gives 2. Many programming languages round the quotient toward zero instead, so −7 = 3 × (−2) − 1 gives −1. Python’s % follows the math rule.
What is a modular inverse?
The number x with a × x mod n = 1. It plays the role of division in modular arithmetic. It exists only when a and n have no common factor (their greatest common divisor is 1).
How can it compute such big powers?
By squaring: 3²⁰⁰ is built from 3, 3², 3⁴, 3⁸ and so on, reducing modulo n after every step, so the numbers never grow. That’s the same method cryptography uses.
Link with pre-filled values
Add # and these parameters to the end of this page's address to open the tool with values already filled in.
| Parameter | What it sets |
|---|---|
a | The number (whole, may be negative). |
n | The modulus (whole, greater than 0). |
e | Optional exponent for aᵉ mod n. |
Example: https://toolabelle.com/modulo-calculator/#a=-7&n=3&e=200