Modulo Calculator

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

a mod n
—
Division
—
Remainder as in C, Java, JavaScript (a % n)
—
Modular inverse of a
—

Extended Euclidean algorithm

abQuotientRemainder

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

  1. Enter the number a and the modulus n.
  2. Optionally enter an exponent e to compute aᵉ mod n.
  3. 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.

ParameterWhat it sets
aThe number (whole, may be negative).
nThe modulus (whole, greater than 0).
eOptional exponent for aᵉ mod n.

Example: https://toolabelle.com/modulo-calculator/#a=-7&n=3&e=200

Related tools