AI Tools Free

Modulo Calculator

Enter an integer dividend (a) and a nonzero integer divisor (b) between -1,000,000,000 and 1,000,000,000 into this modulo calculator to evaluate the non-negative Euclidean remainder (0 <= r < |b|) in one click.

Free to useNo sign-upRuns in your browser
Enter your details

Enter the inputs, then select Calculate result.

Your result
Enter your details

Result will appear here

Euclidean modulo formula and how this modulo calculator works

The Modulo Calculator is a browser-based modular arithmetic utility that computes the canonical non-negative Euclidean remainder (a mod |b|) for any integer dividend and nonzero integer divisor between -1 billion and 1 billion. Unlike C or JavaScript % operators that return negative values on negative dividends, this modular calculator always returns a remainder r in the range 0 <= r < |b|.

r = ((a % |b|) + |b|) % |b|, where b ≠ 0 and 0 <= r < |b|.

Normalizes the divisor to |b| = Math.abs(b) and shifts negative JavaScript remainders upward into [0, |b|) (see our Long Division Calculator, Modular Exponentiation Calculator, and Diophantine Equation Solver).

Diagram showing 17 mod 5 = 2 (17 = 5 × 3 + 2) and -17 mod 5 = 3 (-17 = 5 × (-4) + 3)
With Integer dividend = 17 and Nonzero integer divisor = 5, the Euclidean remainder is 2; for -17 and 5, it is 3.

Euclidean Modulo vs Python and JavaScript Remainder Reference Table

Compare 10 benchmark cases showing how this modular arithmetic calculator's Euclidean remainder (0 <= r < |b|) compares against Python's floored % operator and JavaScript/C/Java's truncated % operator.

Modulo ScenarioDividend (a)Divisor (b)Euclidean Modulo (a mod |b|)Euclidean Equation (a = b × q + r)Python Floored (a % b)JS / C / Java (a % b)
Preloaded positive example175217 = 5 × 3 + 222
Negative dividend (-17 mod 5)-1753-17 = 5 × (-4) + 33-2
Negative divisor (17 mod -5)17-5217 = (-5) × (-3) + 2-32
Both negative (-17 mod -5)-17-53-17 = (-5) × 4 + 3-2-2
24-hour clock wrap (-3 mod 24)-32421-3 = 24 × (-1) + 21 (21:00)21-3
7-day weekday shift (100 mod 7)10072100 = 7 × 14 + 222
Caesar cipher alphabet wrap (-4 mod 26)-42622-4 = 26 × (-1) + 2222-4
Exact multiple (144 mod 12)144120144 = 12 × 12 + 000
Dividend smaller than divisor (3 mod 8)3833 = 8 × 0 + 333
Zero dividend (0 mod 5)0500 = 5 × 0 + 000

How to calculate modulo in 3 steps

Follow these three steps to find the non-negative Euclidean remainder for any pair of signed integers.

Enter the integer dividend

Type any whole number a from -1,000,000,000 to 1,000,000,000 into the Integer dividend field (17 is preloaded by default).

Input and settings
Modulo Calculator input fields populated with Integer dividend 17 and Nonzero integer divisor 5
Step 1: Enter the integer dividend and nonzero divisor within ±1,000,000,000.

Enter the nonzero integer divisor

Specify a nonzero modulus b (5 by default, within ±1 billion) in the Nonzero integer divisor box.

Tool result
Modulo Calculator result panel showing 2 for 17 mod 5
Step 2: Click Calculate result to evaluate ((a % |b|) + |b|) % |b|.

Click Calculate result and export the remainder

Press Calculate result to compute the non-negative remainder r, then click Copy or Download (result.txt) to save the output.

Review the details
Modulo Calculator output panel with Copy and Download result.txt buttons
Step 3: Copy the remainder or download result.txt.

Modulo operator calculator examples: negative dividends and clock math

See how developers and math students use this modulo operator calculator across positive remainders, negative wrap-around indices, and clock or cipher arithmetic.

Positive integer remainder (17 mod 5 = 2)

With the preloaded values Integer dividend = 17 and Nonzero integer divisor = 5, clicking Calculate result returns 2. Because 5 × 3 = 15 is the largest multiple of 5 less than or equal to 17, the remainder is 17 - 15 = 2. Whenever a and b are both positive, Euclidean modulo, Python %, and JavaScript % all return the same remainder 2 (and if you want the quotient 3 displayed alongside the remainder 2, use our Long Division Calculator).

Worked example showing 17 mod 5 = 2 since 17 = 5 × 3 + 2
Dividing 17 by 5 leaves a remainder of 2 above 5 × 3 = 15.

Negative dividend modulo (-17 mod 5 = 3)

When Integer dividend = -17 and Nonzero integer divisor = 5, truncated division in C, Java, or JavaScript evaluates -17 / 5 = -3 and leaves a negative remainder (-17 - 5 × (-3) = -2). In number theory and cryptography, however, remainders in mod 5 must belong to the canonical residue set {0, 1, 2, 3, 4}. Stepping down to the floor quotient -4 gives 5 × (-4) = -20, so -17 - (-20) = 3. This calculator applies ((-17 % 5) + 5) % 5 and returns 3.

Worked example contrasting Euclidean -17 mod 5 = 3 (-17 = 5 × (-4) + 3) with truncated -17 % 5 = -2
For -17 mod 5, stepping down to the floor multiple -20 yields a non-negative remainder of 3.

24-hour clock arithmetic and Caesar cipher shifts (-3 mod 24 = 21)

Modular wrap-around keeps cyclic indices inside fixed bounds [0, m - 1]. Subtracting 5 hours from 02:00 on a 24-hour clock gives a = 2 - 5 = -3; entering -3 and 24 returns 21 (21:00, or 9:00 PM). Likewise, shifting letter index 0 (A) backward by 4 positions in a 26-letter alphabet (-4 mod 26) returns index 22 (W), which is the exact modular wrap used in our Caesar Cipher Decoder.

Worked example showing -3 mod 24 = 21 on a 24-hour cycle and -4 mod 26 = 22 on a 26-letter cipher wheel
Cyclic wrap-around maps -3 mod 24 to 21:00 and -4 mod 26 to index 22.

Interpreting Euclidean modulo vs truncated and floored % operators

Programming languages and mathematics textbooks define the modulo operation in three different ways when negative numbers are involved:

First, Euclidean modulo (0 <= r < |b|, used by this tool) chooses the integer quotient q so the remainder r = a - b × q is always non-negative and strictly smaller than |b|, regardless of the signs of a and b. Thus 17 mod 5 = 2, -17 mod 5 = 3, 17 mod -5 = 2, and -17 mod -5 = 3.

Second, floored modulo (used by Python and R) uses q = floor(a / b), which matches Euclidean modulo when b > 0 (-17 % 5 == 3) but returns a negative remainder when b < 0 (17 % -5 == -3). Third, truncated remainder (used by JavaScript, C, C++, Java, and Rust %) rounds q toward zero, so -17 % 5 returns -2.

Comparison of Euclidean (0 <= r < |b|), floored (sign of b), and truncated (sign of a) remainders
Euclidean modulo guarantees 0 <= r < |b| across all sign combinations.

Modular calculator input rules (±1B) and nonzero divisor limits

Check these three constraints before running a calculation:

First, entering 0 in Nonzero integer divisor (#b) is mathematically undefined and triggers 'The divisor cannot be zero.' Both Integer dividend (#a) and Nonzero integer divisor (#b) require whole numbers (step=1) between -1,000,000,000 and 1,000,000,000.

Second, to evaluate large powers a^e mod m up to 100 digits, open our Modular Exponentiation Calculator. To solve linear congruences ax ≡ c (mod m) or check coprimality gcd(a, m) = 1, use our Diophantine Equation Solver, GCF Calculator, LCM Calculator, and Continued Fraction Calculator.

Summary of the nonzero divisor rule, ±1 billion integer range, and related modular tools
Requires a nonzero integer divisor and signed whole numbers within ±1,000,000,000.

Frequently asked questions about the modulo calculator

Answers about using Modulo Calculator and understanding its results.

How do you calculate a mod b by hand or on a regular calculator?

Divide the dividend a by the positive divisor b (17 ÷ 5 = 3.4) and take the floor integer q = floor(a / b) (q = 3). Multiply q × b (3 × 5 = 15) and subtract that product from a (17 - 15 = 2) to get the remainder r = 2.

How do you calculate the modulo of a negative number like -17 mod 5?

Divide -17 by 5 (-3.4) and round down toward negative infinity to get the floor quotient q = -4. Since 5 × (-4) = -20, the distance upward from -20 to -17 is -17 - (-20) = 3, which means -17 mod 5 = 3.

Why does JavaScript -17 % 5 return -2 while this modulo calculator returns 3?

JavaScript's % operator is a truncated remainder operator: it rounds the quotient -17 / 5 = -3.4 toward zero (-3) and computes -17 - 5 × (-3) = -2. This calculator uses the Euclidean modulo formula ((a % |b|) + |b|) % |b|, which adds 5 to -2 so the remainder always lies in [0, |b|).

What happens when the dividend is smaller than the divisor (such as 3 mod 8)?

When a non-negative dividend a is strictly smaller than |b| (for example, 3 mod 8 or 0 mod 5), the floor quotient is 0 (3 = 8 × 0 + 3). Subtracting 0 leaves a unchanged, so a mod b simply equals a (3 mod 8 = 3).

Why cannot the divisor b be zero in a mod b?

The modulo operation a mod b is defined as the remainder of dividing a by b (a = b × q + r). Because division by 0 is undefined and no multiple 0 × q can ever reach a nonzero dividend a, a divisor of 0 is rejected with 'The divisor cannot be zero.'

Calculate your Euclidean modulo remainder now

Choose another tool for your next calculation, conversion, or text task.

Calculate result