Skip to content
Advertisement
Hosinger Special Offer

Modular Arithmetic Calculator

Modular Arithmetic Calculator from Gizcalc helps you estimate results quickly within the Math & Statistics category.

  • Instant results
  • Charts & tables
  • Save & compare
  • Private – runs in your browser
a mod m —

Sample inputs are pre-filled so you can see a result quickly. Results are estimates only and may not be accurate because prices, interest rates, taxes, fees, fuel costs, tariffs, market returns, medical costs, and local rules can change. Please verify current values before making financial, tax, legal, medical, or business decisions.

Formula used

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

  • ⌊ ⌋ = rounding down to the nearest whole number
  • m = the modulus (a positive whole number)

About the Modular Arithmetic Calculator

What is the Modular Arithmetic Calculator?

Modular arithmetic is arithmetic that “wraps around” after reaching a fixed number, the modulus. a mod m is the remainder when a is divided by m: 17 mod 5 = 2. A 12-hour clock is the everyday example — 5 hours after 10 o'clock is 3 o'clock, because 15 mod 12 = 3.

Besides the remainder, the calculator finds aᵉ mod m using fast square-and-multiply exponentiation (so exponents up to a trillion are instant) and the modular inverse — the number x with a × x ≡ 1 (mod m) — using the extended Euclidean algorithm. These are the building blocks of RSA encryption.

How to use the Modular Arithmetic Calculator

  1. Number (a) — any whole number; negatives are allowed. (sample: 17)
  2. Modulus (m) — a positive whole number. (sample: 5)
  3. Exponent for aᵉ mod m — the exponent used for aᵉ mod m. (sample: 3)
  4. Press Calculate (results also refresh as you type). The result card shows the a mod m, along with aᵉ mod m, Modular inverse of a and Quotient (a ÷ m, floored).

Formula used

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

  • ⌊ ⌋ = rounding down to the nearest whole number
  • m = the modulus (a positive whole number)

The result is always between 0 and m − 1, even for negative a (−7 mod 5 = 3). A modular inverse exists only when a and m have no common factor, i.e. GCD(a, m) = 1.

Worked example

These are the sample values already filled in the calculator above, and the result it returns for them:

InputSample value
Number (a)17
Modulus (m)5
Exponent for aᵉ mod m3
ResultValue
a mod m2
aᵉ mod m3
Modular inverse of a3
Quotient (a ÷ m, floored)3

Tips for using the Modular Arithmetic Calculator

  • Day-of-week problems: 100 days after a Monday is 100 mod 7 = 2 days later in the week — a Wednesday.
  • ISBN-10 check digits use mod 11, and debit/credit card numbers are validated with the Luhn (mod 10) check.
  • In many programming languages the % operator returns a negative result for negative inputs; this calculator always returns a value from 0 to m − 1.

Frequently asked questions

2, because 17 = 5 × 3 + 2.

The modular inverse of a (mod m) is the number x such that a × x leaves remainder 1 when divided by m. For a = 2 and m = 5 it is 3, because 2 × 3 = 6 ≡ 1 (mod 5).

RSA encrypts a message m as c = mᵉ mod n and decrypts with m = cᵈ mod n, where d is the modular inverse of e. Fast modular exponentiation makes these huge powers practical.

Find the multiple of m just below the number. −7 = 5 × (−2) + 3, so −7 mod 5 = 3.