Modulo Calculator (a mod n)

a mod n: remainder of a divided by n. Always non-negative for positive n.

Inputs

Result

Loading calculator…

How to use this calculator

  • Enter a and n.
  • Read mathematical mod (always 0..n−1) and JS-style mod (signed).

About this calculator

Modulo (a mod n) returns the remainder when a is divided by n. For positive operands: 17 mod 5 = 2 (since 17 = 3 × 5 + 2). For negative dividends, conventions differ: math mod is always non-negative (−7 mod 5 = 3); programmer's remainder follows sign of dividend (-7 % 5 = -2 in JS/C/Java). Used in cryptography, hashing, cyclic structures (clocks, calendars), and array indexing.

Frequently asked

Why two answers?+
Math mod follows Euclidean division (always non-negative). C/Java/JS "remainder" follows sign of dividend. Python's % matches math mod.
When does the difference matter?+
Only with negative dividends. -7 mod 5: math = 3 (clock-wraps), JS % = -2.
Modular arithmetic use?+
Hashing, cryptography (RSA, ECC), random number generators, cyclic schedules ("every 7th day").
a mod 0?+
Undefined — division by zero. Calc returns "undefined".
Modular inverse?+
Exists if gcd(a, n) = 1. Computed via extended Euclidean algorithm.

Related calculators

More tools you might like

Hand-picked tools that pair well with this one — same audience, same intent.