Calculator Uni

Modulo Calculator

Find remainders with correct handling of negative numbers.

a mod n

-17 mod 5

3

JavaScript % operator gives

-2

Quotient (floored)

-4

Clock arithmetic

Modulo keeps the remainder after division — 17 mod 5 is 2, and clocks are mod 12: 9 + 5 o'clock wraps to 2. The mathematical convention keeps results in 0…n−1 even for negatives: −17 mod 5 is 3, since −17 = −4×5 + 3.

The negative-number trap

Most programming languages' % operator returns −2 for −17 % 5, following the dividend's sign — a classic off-by-wrap bug in calendars and array indexing. The fix shown here, ((a % n) + n) % n, is a rite of passage.

Frequently asked questions

How does the Modulo Calculator work?
Find remainders with correct handling of negative numbers.
Is the Modulo Calculator free to use?
Yes. The Modulo Calculator is completely free, runs entirely in your browser, and requires no account or sign-up. Your inputs never leave your device.

Related calculators