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

    Frequently Asked Questions

    What is modular arithmetic?

    Modular arithmetic deals with remainders. "a mod m" is the remainder when dividing a by m. Think of it like clock arithmetic: 14:00 mod 12 = 2:00.

    What is congruence?

    Two numbers are congruent modulo m if they have the same remainder when divided by m. Written as a ≡ b (mod m). For example, 17 ≡ 2 (mod 5).

    Where is modular arithmetic used?

    It is fundamental to cryptography (RSA, Diffie-Hellman), computer science (hash tables), error detection (checksums), and everyday life (clock times, days of the week).

    Ready to run the numbers?

    Open Modular Arithmetic Calculator