CalcWorldHub
Free online calculator · no signup

Modular arithmetic calculator

Add, subtract, or multiply integers and reduce the result modulo a positive integer.

4,000 tools
Modular arithmetic calculator — First integer, Second integer, Modulus m and calculation method
Modular arithmetic calculator: inputs and calculation method.

How to use this calculator

Add, subtract, or multiply integers and reduce the result modulo a positive integer.

  1. Enter First integer, Second integer, Modulus m, Operation. Match the units shown beside each field and review the result together with the assumptions below.
  2. Read the worked example below to check the expected input format and result.
  3. Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Math guide

How this calculation works

Modular arithmetic keeps the remainder after division by a positive modulus. The result is normalized into the range from zero through one less than the modulus, including when subtraction or multiplication first produces a negative or large integer.

Inputs and meanings

a — First integer
Enter an integer from −10,000,000 to 10,000,000.
b — Second integer
Enter an integer in the same range.
modulus — Modulus m
Enter a positive integer modulus.
operation — Operation
Choose the integer operation.

Formula and method

a + b (mod m), a − b (mod m), or ab (mod m), normalized to a remainder in 0,…,m−1.

The raw integer result is reduced with a nonnegative Euclidean remainder. This convention produces the same residue class for negative operands.

Worked example

For 17 + 23 modulo 7, first add to get 40; 40 = 5×7 + 5, so the normalized result is 5. As a negative-input check, −3 modulo 7 is 4 because −3 = (−1)×7 + 4.

Assumptions and limits

Operands and modulus are limited to integers of manageable size so multiplication remains exact in JavaScript number arithmetic.

Frequently asked questions

What does “modulo m” mean?

It groups integers by their remainder after division by m.

Why is a negative result shown as a positive remainder?

This tool uses the Euclidean convention, returning a value from 0 through m−1.

Can I divide modulo m here?

No. Modular division requires a modular inverse and is a separate operation.

How do I use the Modular arithmetic calculator?

Enter First integer, Second integer, Modulus m, Operation. Match the units shown beside each field and review the result together with the assumptions below.

What is a worked example of Modular arithmetic?

For 17 + 23 modulo 7, first add to get 40; 40 = 5×7 + 5, so the normalized result is 5. As a negative-input check, −3 modulo 7 is 4 because −3 = (−1)×7 + 4.