Find a mod b for negative numbers, decimals or 300-digit integers, see how Python, Excel and JavaScript differ, and get powers mod n, remainder tables and divisibility checks.
What is the last digit of 9^100?
Find a mod b for negative numbers, decimals or 300-digit integers, see how Python, Excel and JavaScript differ, and get powers mod n, remainder tables and divisibility checks.
The calculator below is set to base 9, exponent 100 and modulus 10, because the last digit (the unit digit) of a number is its remainder mod 10. Press Calculate for the last digit of 9100, the short cycle that the last digits of powers of 9 repeat, and where the 100th power lands in it. Use modulus 100 for the last two digits.
Parameters
Enter data for calculations
💡 Fill in all required fields to unlock the calculate button
Modulo and remainders, with the sign rule spelled out
Ask Python for -7 mod 3 and it says 2; ask JavaScript and it says -1. Both are right under their own rules, and this modulo calculator prints both, plus the Euclidean remainder that number theory uses, so you can see which one your code or your homework expects. It works on whole numbers of any length (a 31-digit number is no problem), on decimals such as 7.5 mod 2 = 1.5 without floating-point noise, and it has three more modes: a power mod n such as the last digit of 7100, a table of remainders for a range, and a divisibility check against a list of divisors.
17 and 5, and the answer is 2, because 17 = 5 × 3 + 2. Negative or decimal inputs work the same way; the table under the result shows how each convention treats them.
What each mode needs from you
- What do you want to calculate - a remainder a mod b, a power mod n, a table of remainders, or a divisibility check.
- Dividend a and divisor b - any whole numbers or decimals, negative allowed, b not zero. Type digits without thousands separators.
- Base, exponent and modulus - for a power mod n. The exponent may have hundreds of digits; the modulus must be 1 or more.
- Divisor, first and last number - for the table, up to 200 numbers in one range.
- Number to check and a list of divisors - separated by commas or spaces, for example 2, 3, 5, 7, 11.
- Read the headline answer, the tiles (quotient, Euclidean remainder, the JavaScript result, the cycle of powers) and the table below it.
Eight everyday jobs a remainder does
Example 1: what the clock says after 100 hours
Situation: it is 9:00 now, what time will it be in 100 hours?(9 + 100) mod 24Result: 109 mod 24 = 13, so 13:00, which is 1 p.m., four days later.
Example 2: the weekday 45 days from a Monday
Situation: number the days Monday = 0 to Sunday = 6.45 mod 7Result: 3, so a Thursday. Six full weeks pass and three days are left over.
Example 3: seconds into minutes and seconds
Situation: a timer shows 1000 seconds.1000 mod 60Result: quotient 16, remainder 40: 16 minutes 40 seconds.
Example 4: the check digit of an ISBN-10
Situation: the first nine digits are 0-306-40615. Multiply them by 10, 9, ..., 2 and add: 130.130 mod 11Result: the remainder is 9, and the check digit is 11 - 9 = 2, giving 0-306-40615-2.
Example 5: the last digit of 7 to the 100th power
Situation: the power mod n mode, base 7, exponent 100, modulus 10.7^100 mod 10Result: 1. Last digits of powers of 7 repeat 7, 9, 3, 1 every four steps, and 100 is a multiple of 4.
Example 6: a power far too big to write out
Situation: 3200 has 96 digits.3^200 mod 7Result: 2, reached by repeated squaring with every step reduced mod 7.
Example 7: a negative number in code
Situation: an array index that moves left past the start.-7 mod 3Result: Python and spreadsheets give 2, a valid index; JavaScript, C and Java give -1, which crashes the lookup.
Example 8: a remainder with decimals
Situation: how much of a 7.5 m board is left after cutting 2 m pieces?7.5 mod 2Result: three pieces and 1.5 m left, exactly. In floating point, 0.3 mod 0.1 comes out as 0.09999999999999998; here it is 0.
-7 mod 3 and 7 mod -3 in each language
The remainder must satisfy a = b × q + r in every convention; they differ only in how the quotient q is rounded, and that decides the sign of r.
| Where | -7 mod 3 | 7 mod -3 | Rule |
|---|---|---|---|
| Python %, Excel and Google Sheets MOD, R %% | 2 | -2 | quotient rounded down, sign of the divisor |
| JavaScript, C, C++, Java, C# % | -1 | 1 | quotient cut toward zero, sign of the dividend |
| Java Math.floorMod | 2 | -2 | the floor rule, added for this exact problem |
| Euclidean remainder (number theory) | 2 | 1 | always from 0 to |b| - 1 |
When both numbers are positive all four rows agree, which is why the difference goes unnoticed until the first negative input.
Last digits of powers repeat
The power mod n mode finds these cycles on its own; for mod 10 they are the patterns behind "what is the last digit of" questions.
| Base | Last digits of base1, base2, ... | Cycle length |
|---|---|---|
| 2 | 2, 4, 8, 6 | 4 |
| 3 | 3, 9, 7, 1 | 4 |
| 4 | 4, 6 | 2 |
| 7 | 7, 9, 3, 1 | 4 |
| 8 | 8, 4, 2, 6 | 4 |
| 9 | 9, 1 | 2 |
| 5 and 6 | always 5, always 6 | 1 |
Modulo questions, answered with numbers
Related tools
Binomial Expansion Calculator
Exact binomial coefficients and expansions, including very large C(n, k) - See calculator
Conditional Probability Calculator
Two-way tables, Bayes' theorem and test accuracy in exact fractions - See calculator
GCD & LCM Calculator
The Euclidean algorithm, which is repeated modulo from start to finish - See calculator
Prime Factorization Calculator
Every divisor of a number at once, from its prime factors - See calculator
Prime Number Calculator
Whether a number has any divisor besides 1 and itself - See calculator
Number System Converter
Binary, octal and hexadecimal, where each digit comes from a repeated remainder - See calculator
See also
Calculator verified by the LiczGrupa.pl team
Content, formulas and results have been reviewed for accuracy and relevance by our team of specialists.

Reviewed by: Natalia Skrzek