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.
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.
Frequently asked questions
What happens if I divide by zero?
Why does Python give a different sign than JavaScript for -7 % 3?
Is mod the same as % in math notation?
How do I get a strictly non-negative remainder?
Related Tools
Complex Number Modulus and Phase (Polar Form)
Enter the real and imaginary parts of z to get the magnitude sqrt(a^2 + b^2) and the argument atan2(b, a), reported in radians and in degrees.
Flexural Modulus of Rupture (Ceramic)
Compute the three-point flexural modulus of rupture (MOR) of a ceramic, MOR = 3·F·L/(2·b·d²), from the breaking load (F), the support span (L), the width (b) and the thickness (d) of the test bar. It is the main mechanical-strength measure of ceramics and tiles (ISO 10545): porcelain tiles exceed 35 MPa. The d² dependence shows why thicker pieces resist far more. Enter the load, the support span, the width and the thickness.
Rubber Apparent Compression Modulus
Computes the apparent compression modulus of a rubber block squeezed between two bonded plates, Ec = E₀ × (1 + 2 × k × S²), where E₀ is the Young's modulus of the compound, k is a numerical constant tabulated by hardness (running from about 0.93 for soft 30 IRHD rubber to 0.53 for hard 75 IRHD) and S is the shape factor, which for a circular block equals the diameter divided by four times the thickness. Rubber is essentially incompressible in volume, so what resists the load is not compression of the material but friction on the bonded faces, which stops the sides from bulging; that is why the apparent modulus can sit many times above the compound's own Young's modulus. The result, in megapascals, is what you use to get the vertical stiffness of the mount (stiffness = Ec × area ÷ thickness) and from there the natural frequency of the isolated system. Because the shape factor is S = D ÷ 4t and the dominant term goes with S squared, diameter and thickness are levers of equal weight and opposite sign: halving the thickness and doubling the diameter do exactly the same thing, and in the example both take the apparent modulus from 11.3 to 35.3 MPa — a thin mount is a stiff mount, and that ruins vibration isolation. Enter the compound's Young's modulus, the constant k, the block diameter and the thickness.
Star Distance Modulus Calculator
Computes distance modulus m - M and equivalent distance in parsecs from apparent and absolute star magnitudes.
Riser Modulus
Calculate the minimum modulus of a riser (feeder) by the modulus rule, M_riser = 1.2 × M_part, from the part's cooling modulus. The result, in cm, is the modulus the riser must have to solidify after the part (about 20% slower) and feed it with molten metal during solidification shrinkage, avoiding shrinkage cavities. The riser is a metal reservoir placed over the thickest region of the part; if it solidifies first, it fails its purpose. From the modulus, the riser geometry is sized. It is a fundamental rule of casting design. Enter the part's cooling modulus.
Solidification Time (Chvorinov)
Calculate the solidification time of a casting by Chvorinov's rule, t = B × (V ÷ A)², from the mold constant B (min/cm², depending on the mold material and metal) and the ratio of the part's volume V to its surface area A. The result, in minutes, is the time for the metal to fully solidify. The rule shows that parts with a higher volume/area ratio (more 'massive') solidify more slowly — a fundamental casting design principle: risers (metal reservoirs) must have a larger modulus than the part to solidify last and feed the shrinkage. Enter the mold constant, the volume and the part area.
The results provided by this tool are for general informational and educational purposes only and do not constitute professional, financial, medical, legal, tax or accounting advice. Always confirm important decisions with a qualified professional and official sources.