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.
| a | m | a mod m | What it means |
|---|---|---|---|
| 17 | 5 | 2 | 17 = 3 x 5 + 2, so 2 is left over |
| 7 | 10 | 7 | a is smaller than m, so the remainder is a itself |
| 100 | 7 | 2 | 100 = 14 x 7 + 2 |
| 365 | 7 | 1 | A 365-day year is 52 whole weeks plus 1 day |
| 25 | 12 | 1 | 25 hours on a 12-hour clock lands on 1 o'clock |
| 50 | 24 | 2 | 50 hours is 2 full days plus 2 hours |
| 1,000 | 9 | 1 | Matches the digit-sum test: 1 + 0 + 0 + 0 = 1 |
| -7 | 3 | 2 | Wraps forward to 2, not back to -1 |
| -1 | 12 | 11 | One hour before 12 o'clock is 11 o'clock |
| -15 | 4 | 1 | -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
Ratio Calculator
Express a ratio as a decimal and percentage.
OpenProportion Calculator
Solve for the unknown in a proportion (cross-multiplication).
OpenStandard Deviation Calculator
Sample and population standard deviation from a dataset.
OpenMean, Median, Mode Calculator
Central tendency: mean, median, and mode.
OpenLast updated: September 6, 2026