Modulo Calculator: a mod n and Remainders

Use this modulo calculator to find a mod n in one step. Enter any two whole numbers, including negatives, and get the remainder, the quotient and the steps. It is handy for coding, clock math and number puzzles.

Modulo Calculator

Remainders and modular powers.

-
Everything runs in your browser. Nothing you enter or upload is sent to a server.

How to use the Modulo Calculator

  1. Enter the number a and the divisor n.
  2. Read a mod n.
  3. Compare the math and programming remainders for negative numbers.
  4. Add a power to compute a^p mod n.

How it works

a mod n is the remainder after dividing a by n. Math and Python use the floored definition, so the answer is always between 0 and n − 1. JavaScript, C and Java use truncation, so the remainder takes the sign of a. Modular powers use fast square-and-multiply with exact BigInt numbers.

Example

17 mod 5 = 2. For −17 mod 5 the math answer is 3 while JavaScript −17 % 5 gives −2.

Frequently asked questions

What is 10 mod 3?

1, because 10 = 3 × 3 + 1.

Why does a negative mod give two answers?

Languages define the remainder differently; both are shown.

What is modulo used for?

Clocks, calendars, cryptography, hashing and checking even or odd.

See also: Long Division Calculator, Big Number Calculator.

Find a mod n

How to use it

  1. Enter the number a.
  2. Enter the divisor n.
  3. Read the remainder.
  4. Check the steps.

More questions

What is 17 mod 5?

2, because 17 is 3 times 5 plus 2.

How are negatives handled?

It shows the math result and notes how some languages differ.

Where is mod used?

Mod is used in code, clocks, calendars and checksums to find remainders.

Related tools: Number Base Converter, Factorial Calculator, Binary Calculator.