Modular Arithmetic Calculator

Check whether two integers are congruent, find a modular multiplicative inverse, or calculate a large power modulo m. The tool uses exact integer arithmetic and runs privately in your browser.

Choose a calculation

Signed whole numbers are accepted.

Enter a positive integer of at least 2.

Private by design: entered integers are validated and calculated on this device. They are not uploaded, stored, or added to the page URL.

Result

The congruence example is calculated below.

Advertisement

Modular arithmetic definitions

Congruence

a ≡ b (mod m) ⇔ m | (a − b)

Two integers are congruent when their difference is divisible by the positive modulus.

Modular inverse

a·x ≡ 1 (mod m)

An inverse exists exactly when gcd(a, m) = 1. The extended Euclidean algorithm finds x.

Modular power

r ≡ aᵉ (mod m)

Binary exponentiation repeatedly squares the base and reduces after every multiplication, avoiding construction of the full power.

For a positive modulus m, this calculator reports the canonical residue r satisfying 0 ≤ r < m. This convention makes the displayed answer consistent even when an input is negative.

Worked examples

Congruence

38 ≡ 14 (mod 12) because both canonical residues are 2. Equivalently, 38 − 14 = 24 = 2·12.

Modular inverse

The inverse of 17 modulo 43 is 38 because 17·38 = 646 = 15·43 + 1. Therefore 17·38 ≡ 1 (mod 43).

Modular power

7¹²⁸ mod 13 = 3. Repeated squaring evaluates it with eight binary-exponentiation rounds instead of multiplying 7 by itself 127 times.

Method, assumptions, and limits

Every input must be a base-10 integer written without commas, decimal points, scientific notation, or arithmetic expressions. A leading plus or minus sign is accepted where signed input is meaningful. The modulus must be a positive integer of at least 2, and modular-power exponents must be nonnegative. For exponent 0, the calculator uses the empty-product convention a⁰ = 1, including when the entered base is 0.

Congruence is tested both by comparing canonical residues and by checking divisibility of a − b. Inverses are calculated with the extended Euclidean algorithm after reducing a modulo m. Powers use exponentiation by squaring, so work grows with the number of binary digits in the exponent rather than with the exponent itself.

Each input is limited to 200 digits, excluding an optional sign. Calculations use JavaScript BigInt, so results are exact integers rather than floating-point approximations. The on-screen power trace is limited to the first 24 rounds; the final result still uses every round.

Calculation note: definitions, sign handling, existence conditions, and the representative examples were checked against the stated identities. Last reviewed: .

Modular arithmetic calculator FAQ

What does a ≡ b (mod m) mean?

It means that m divides a − b. Equivalently, a and b have the same canonical remainder from 0 through m − 1.

How do I find a positive remainder for a negative number?

Reduce the number modulo m and, if the programming-language remainder is negative, add m. The calculator always reports the canonical residue in the range 0 through m − 1.

When does a modular inverse exist?

An integer a has a multiplicative inverse modulo m exactly when gcd(a, m) = 1. If the GCD is larger than 1, no integer can multiply a to produce residue 1.

Can a modular inverse have more than one value?

All integers congruent to the reported inverse work. The calculator reports the unique canonical representative between 0 and m − 1.

How are large modular powers calculated?

The tool uses binary exponentiation, also called repeated squaring. It reduces modulo m after each multiplication, so it never needs to store the generally enormous value of aᵉ.

Can the exponent be negative?

This calculator accepts nonnegative exponents. A negative exponent would first require a modular inverse of the base, and that inverse does not always exist.

Why must the modulus be at least 2?

This tool uses the standard computational convention of a positive modulus with at least two residue classes. It therefore rejects zero, negative moduli, and modulus 1.

Does the calculator store my integers?

No. Validation, calculation, and copy preparation run locally in your browser. The tool does not transmit or save entered values.

Explore more tools