Modular Arithmetic Calculator Formula

Understand the math behind the modular arithmetic calculator. Each variable explained with a worked example.

Formulas Used

A Mod M

a_mod_m = mod(a, m)

B Mod M

b_mod_m = mod(b, m)

Add Mod

add_mod = mod(a + b, m)

Mult Mod

mult_mod = mod(a * b, m)

Quotient

quotient = floor(a / m)

Variables

VariableDescriptionDefault
aNumber (a)17
mModulus (m)5
bSecond Number (b)8

How It Works

Modular Arithmetic

Definition

a mod m gives the remainder when a is divided by m.

For example, 17 mod 5 = 2 because 17 = 3 × 5 + 2.

Key Properties

  • (a + b) mod m = ((a mod m) + (b mod m)) mod m
  • (a × b) mod m = ((a mod m) × (b mod m)) mod m
  • Applications

    Modular arithmetic is used in cryptography (RSA), hash functions, clock arithmetic, and check digit algorithms (ISBN, credit cards).

    Worked Example

    Calculate modular operations with a = 17, b = 8, m = 5.

    a = 17m = 5b = 8
    1. 0117 mod 5 = 2 (17 = 3×5 + 2)
    2. 028 mod 5 = 3 (8 = 1×5 + 3)
    3. 03(17+8) mod 5 = 25 mod 5 = 0
    4. 04(17×8) mod 5 = 136 mod 5 = 1

    Ready to run the numbers?

    Open Modular Arithmetic Calculator