Modulo Calculator
Calculate the remainder of integer division (modulo) between two numbers. Instant result in the browser.
What is the division remainder?
Euclidean division follows the relation dividend = divisor × quotient + remainder, with the condition 0 ≤ remainder < divisor. In code, the operator that hands back that remainder is modulo (%). Take 17 ÷ 5: the quotient is 3 and what is left over is 2.
You will run into this calculation everywhere, whether you are checking if a number is even or odd, handling cycles, building hash functions or even feeding cryptographic algorithms.
What the remainder is and the modulo operation
Integer division of a by b produces a quotient q = ⌊a / b⌋ and a remainder r = a - q · b, with 0 ≤ r < |b| in the mathematical convention. Dividing 17 by 5: 17 = 3 · 5 + 2, so quotient is 3 and remainder is 2. The remainder is also called the result of the modulo operation, written a mod b or a % b in most programming languages.
Negative operands expose a real gotcha: the sign of the remainder is not the same across languages. In C, C++, Java, JavaScript and Go, the result follows the sign of the dividend, so -7 % 3 = -1. In Python and Ruby, the result follows the sign of the divisor, so -7 % 3 = 2. Both satisfy a = q · b + r, but the floor versus truncated division choice differs. Always test edge cases when porting code between ecosystems.
Practical applications
- Parity test:
n % 2 == 0for even,!= 0for odd. - Cycle wraparound: day of the week with
days % 7, hours of the day withhours % 24. - Hashing: distributing keys across N buckets with
hash(key) % N. - Public-key cryptography (RSA, Diffie-Hellman) and elliptic-curve schemes rely on modular arithmetic over very large primes.
- Check digits: CPF, CNPJ, barcodes (EAN-13), ISBN, IBAN and credit-card Luhn all use weighted sums modulo 10, 11 or 97.
- Bounded randomization: picking an index in an array via
rand() % length.
FAQ
What happens if I divide by zero? Both quotient and remainder are undefined. Most languages raise an exception or return NaN; this tool blocks the operation and shows an error.
Why does Python give a different sign than JavaScript for -7 % 3? Python uses floor division (rounds toward minus infinity); JavaScript uses truncated division (rounds toward zero). Both keep the identity a = q · b + r, but the pair (q, r) is different.
Is mod the same as % in math notation? Almost. In number theory, a ≡ b (mod n) states a congruence relation rather than a single value, but the everyday programming use overlaps.
How do I get a strictly non-negative remainder? Use ((a % b) + b) % b — this normalizes the result to the range [0, b) regardless of the language convention.
Related Tools
Rent Adjustment Calculator
Compute annual rent adjustment by IGP-M or IPCA accumulated in the last 12 months (manually configurable).
Pregnancy Calculator
Compute estimated due date (EDD), gestational age and trimester from the last menstrual period (LMP).
Fertile Period Calculator
Compute fertile window and ovulation day from the first day of the last cycle and the average cycle length.
Calculate the remainder (modulo)
The remainder of an integer division, the so-called modulo operation, gives back more than it seems. It's what tells whether a number is even or odd, whether one quantity fits exactly into another or where an item lands within a cycle. Here you calculate the remainder between two numbers.
Enter the dividend and the divisor; back come the integer quotient and the remainder. In programming it's everywhere, and it also helps with maths problems, when distributing items into groups or to see cycles and repetitions. It's a small calculation with plenty of uses.
Instead of long division on paper, the calculation runs in the browser. A direct reference for anyone who needs the modulo operation.