Modulo Calculator
Enter a dividend and a divisor to find the remainder. For negative numbers the calculator shows both common conventions, since programming languages differ.
Result
- Quotient (floored)
- 3
- Check
- 5 × 3 + 2 = 17
- Remainder with truncated division (C, Java, JavaScript %)
- 2
- Quotient with truncated division
- 3
The first result takes the sign of the divisor, as in mathematics and in Python. The truncated form takes the sign of the dividend, as the % operator does in C, Java and JavaScript. The two agree when both numbers are positive.
Formula
- a mod n = a − n × ⌊a ÷ n⌋
- a = n × quotient + remainder, with 0 ≤ remainder < n for positive n
How the Modulo Calculator works
The modulo operation gives the remainder when one whole number is divided by another. Seventeen divided by five is three with two left over, so 17 mod 5 is 2.
Modular arithmetic wraps around like a clock. Hours are counted mod 12, and days of the week mod 7. It is the foundation of hashing, checksums and public-key cryptography.
Worked example
17 mod 5: 17 ÷ 5 = 3 remainder 2, because 5 × 3 + 2 = 17. So 17 mod 5 = 2.
Frequently asked questions
What is −7 mod 3?
In mathematics and Python it is 2, because −7 = 3 × (−3) + 2. In C, Java and JavaScript, −7 % 3 gives −1, because those languages truncate the quotient toward zero.
How do I tell if a number is even with modulo?
A number is even when n mod 2 equals 0 and odd when it equals 1.
Related calculators
- Long Division CalculatorDivide whole numbers and see every step of the long division, with the quotient, remainder, mixed number and decimal answer.
- Factor CalculatorFind all factors of a number, its factor pairs and its prime factorization. Also tells you whether the number is prime.
- GCF Calculator (Greatest Common Factor)Find the greatest common factor of two or more numbers, with the Euclidean algorithm steps and prime factorizations. Also gives the LCM.
- Ratio CalculatorSimplify a ratio, solve for a missing value in A : B = C : D, or split a total in a given ratio. Works with whole numbers and decimals.
- Proportion CalculatorSolve a proportion a/b = c/d for the missing value by cross-multiplication. Enter any three of the four numbers.
- LCM Calculator (Least Common Multiple)Find the least common multiple of two or more numbers, with prime factorizations. Also gives the greatest common factor.
- Rounding CalculatorRound a number to the nearest whole number, tenth, hundredth, thousandth, ten, hundred or thousand. Exact decimal rounding with no floating point errors.
- Significant Figures CalculatorCount the significant figures in a number and round it to any number of significant figures, with scientific notation.
- Fraction CalculatorAdd, subtract, multiply and divide fractions and mixed numbers. The answer is simplified and shown as a fraction, a mixed number and a decimal.
- Simplify Fractions CalculatorReduce a fraction to its lowest terms and convert an improper fraction to a mixed number, with the greatest common factor used.
- Decimal to Fraction CalculatorConvert a decimal to a fraction in lowest terms, or a fraction to a decimal. Exact conversion for terminating decimals.
Related unit converters
Calculations run in your browser and nothing you enter is sent to a server. Results are provided for general information. Check critical figures independently before relying on them.