Modular Arithmetic Calculator

Compute modular add, multiply, and powers.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Enter a number and a modulus to get the remainder. You can also add, subtract, multiply or raise to a power in modular arithmetic.

How to use

1
Step 1
Enter a and the modulus m.
2
Step 2
Choose the operation.
3
Step 3
Press Calculate to see the remainder and the working.

How it works

a mod m is the remainder when a is divided by m. For example 101 ÷ 10 = 10 remainder 1, so 101 mod 10 = 1. The result is always between 0 and m − 1.

a mod m = a − m × ⌊a ÷ m⌋

Worked example

10 mod 4

Input
a = 10, m = 4
Output
2
Walkthrough
10 = 2 × 4 + 2, so the remainder is 2.

Limitations

  • Integers only, up to 2^53 − 1 in size.
  • The modulus must be positive.
  • A negative exponent uses the modular inverse and needs a coprime to the modulus.

Questions

What is 101 mod 10?
1, because 101 = 10 × 10 + 1.
What is 10 mod 4?
2, because 10 = 2 × 4 + 2.
How do you calculate a mod m by hand?
Divide a by m, drop the decimals, multiply back by m and subtract from a.

Features

  • Remainder with working
  • Modular exponent
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Rectangle area as product of dimensions

    Khan Academy

    Foundational area thinking across math tools.

    Watch on YouTube
  • The essence of calculus

    3Blue1Brown

    Visual calculus story that complements symbolic solvers.

    Watch on YouTube
  • Pi

    Math is Fun

    What π means when calculators return pi-based results.

  • Euler's Number (e)

    Math is Fun

    e for exponential and scientific calculator keys.