GintiCalcEvery calculation

ModLab

Modular Arithmetic Calculator

Always non-negative result: ((a mod m) + m) mod m.

a mod m for the inputs people check most, including negatives

This calculator always returns a non-negative remainder using ((a mod m) + m) mod m, so negative values of a wrap forward rather than coming back negative. Enter a and the modulus m to reproduce any row.

ama mod mWhat it means
175217 = 3 x 5 + 2, so 2 is left over
7107a is smaller than m, so the remainder is a itself
10072100 = 14 x 7 + 2
36571A 365-day year is 52 whole weeks plus 1 day
2512125 hours on a 12-hour clock lands on 1 o'clock
5024250 hours is 2 full days plus 2 hours
1,00091Matches the digit-sum test: 1 + 0 + 0 + 0 = 1
-732Wraps forward to 2, not back to -1
-11211One hour before 12 o'clock is 11 o'clock
-1541-15 = -4 x 4 + 1

Several programming languages return a negative remainder for a negative a, so -7 % 3 evaluates to -1 in C, Java and JavaScript while the mathematical convention used here is 2. If you are porting a formula between a spreadsheet and code, check which convention the other side uses before trusting the sign.

'Clock arithmetic'

a mod m is just the remainder after dividing a by m — the same logic a clock uses: 14 o'clock 'wraps around' to 2 o'clock because 14 mod 12 = 2.

Where it's used

Modular arithmetic underlies cryptography, hashing, checksums, and any 'wraps around' scenario like days of the week or angles on a circle.

Frequently asked questions

What is modular arithmetic?

a mod m is the remainder when a is divided by m. 17 mod 5 = 2 (because 17 = 3×5 + 2). It's 'clock arithmetic' — after reaching m, you wrap back to 0. Days of the week use mod 7, hours use mod 12 or 24.

How does mod work with negative numbers?

−7 mod 3 = 2 (not −1). This calculator always returns a non-negative result using ((a mod m) + m) mod m. Some programming languages return negative remainders, which can cause bugs. The mathematical convention is always non-negative.

Where is modular arithmetic used in computing?

Hash functions (distributing data across buckets), cryptography (RSA encryption is entirely modular arithmetic), checksums (ISBN, credit card Luhn check), circular buffers, and generating pseudo-random numbers all rely on mod operations.

Related Math calculators

You might also like

Last updated: September 6, 2026