Modulo Calculator (a mod n)

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

Inputs

Result

a mod n
2
17 = 3 Ɨ 5 + 2.
  • a17
  • n5
  • a mod n (math)always 0 to nāˆ’12
  • a % n (JS)sign follows a2
  • Quotient (trunc)3
  • Quotient (floor)3
  • Verify3 Ɨ 5 + 2 = 17

Step-by-step

  1. a / n = 17 / 5 = 3.4 → floor = 3.
  2. Math mod = a āˆ’ floor(a/n) Ɨ n = 17 āˆ’ 15 = 2.
  3. JS and math agree (a ≄ 0).

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

Math mod follows Euclidean division (always non-negative). C/Java/JS "remainder" follows sign of dividend. Python's % matches math mod.

Related calculators