🧰 Free ToolBase

Modulo Calculator

Enter a and b to compute a mod b — supports arbitrarily large integers and both remainder conventions

Modulo Operation Explained

Modulo returns the remainder after division. For example, 17 mod 5 = 2 because 17 = 3 × 5 + 2.

Modulo Differences Across Languages

JavaScript/C++: The remainder sign matches the dividend. -13 % 7 = -6 (since -13 = -1 × 7 + (-6)).

Python/Math: The remainder is always non-negative. -13 % 7 = 1 (since -13 = -2 × 7 + 1).

This tool shows both styles, useful for competitive programming and cross-language development.

Real-world Applications

FAQ

What is 17 mod 5?

17 ÷ 5 = 3 remainder 2, so 17 mod 5 = 2. Verification: 3 × 5 + 2 = 17.

How does negative modulo work?

It varies by language: JavaScript returns -13 % 7 = -6 (sign of dividend), Python returns -13 % 7 = 1 (always non-negative). Python's convention aligns better with mathematical congruence classes.

How large can the numbers be?

Using JavaScript BigInt, this calculator supports integers of arbitrary precision — hundreds of digits long. It computes correctly regardless of size.

What are practical uses of modulo in programming?

Common uses: 1) hash table index mapping; 2) circular array indexing (index % N); 3) parity checks (n % 2); 4) pagination; 5) cryptographic algorithms (RSA etc.); 6) day-of-week calculations.

Related Tools

Prime FactorizerScientific CalculatorPercentage CalculatorCombination Calculator