Modular Arithmetic Calculator

Compute a mod n: the remainder, quotient and the division identity.

Your result will appear here

Fill in the fields and press Calculate.

Modular arithmetic is "clock arithmetic": it wraps numbers around at a fixed value, giving the remainder after division. The clock itself is the everyday example — 3 hours after 11 o'clock is 2, not 14, because time works modulo 12. Beyond clocks, it's the backbone of cryptography, checksums, hashing and any cyclic pattern.

Enter a number (a) and a modulus (n), and a mod n — the remainder, the quotient and the check identity — is calculated instantly.

How is it calculated?

What a mod n means

a mod n is the remainder when a is divided by n. It satisfies a = n × quotient + remainder, with the remainder between 0 and n−1. So 17 mod 5 = 2, because 17 = 5 × 3 + 2.

The division identity

Every result comes with its check: a = n × q + r. For 17 mod 5, that's 17 = 5 × 3 + 2 — the quotient (3) and remainder (2) reconstruct the original. The tool shows this identity so the answer is verifiable at a glance.

Negative numbers

Conventions differ for negative a. In the common mathematical convention the remainder is kept non-negative: −7 mod 3 = 2 (since −7 = 3 × (−3) + 2). Some programming languages return −1 instead; the tool follows the non-negative convention.

Where it's used

  • Clocks and calendars: hours modulo 12 or 24, days of the week modulo 7.
  • Cryptography: RSA and Diffie-Hellman are built on modular exponentiation.
  • Checksums and hashing: distributing values into buckets, validating IDs.
  • Cyclic patterns: anything that repeats on a fixed cycle.

Worked example

Compute 17 mod 5: dividing 17 by 5 gives a quotient of 3 with 2 left over, so 17 mod 5 = 2. The check identity confirms it: 17 = 5 × 3 + 2. As a real-world parallel, "what time is it 17 hours after midnight?" is 17 mod 24 = 17 (5 pm), while 30 hours after midnight is 30 mod 24 = 6 (6 am) — the clock wrapping around is modular arithmetic in action.

FAQ

How is a mod n calculated?+

It is the remainder when a is divided by n: 17 mod 5 = 2, because 17 = 5 × 3 + 2. The tool shows the remainder, the quotient and the check identity.

What does "mod" mean in everyday terms?+

It is clock arithmetic — numbers wrap around at n. 3 hours after 11 o'clock is 2, because time runs modulo 12. The remainder after division is the result.

How does modular arithmetic handle negative numbers?+

In the common mathematical convention the remainder stays non-negative: −7 mod 3 = 2. Some programming languages return a negative remainder instead; this tool uses the non-negative convention.

What is the division identity in modular arithmetic?+

a = n × quotient + remainder. For 17 mod 5 it is 17 = 5 × 3 + 2 — the quotient and remainder reconstruct the original number, which verifies the result.

Where is modular arithmetic used?+

In clocks and calendars, cryptography (RSA, Diffie-Hellman), checksums and hashing, and any system with a repeating cycle. It is fundamental to computer science.

What is the range of a mod n?+

The result is always between 0 and n−1. For n = 5 the possible results are 0, 1, 2, 3 and 4.