gizmobench
BrowseDaily

Modulo Calculator

Enter a dividend and divisor to calculate a mod b under three conventions: Euclidean modulo, truncated remainder and floored modulo. Each result keeps its quotient and identity beside it. The same inputs give additive and multiplicative inverses with the absolute divisor as modulus, plus Euclidean algorithm steps. Caret or double-star powers have expansion steps; expanded operands are limited to 1,000 digits.

Euclidean modulo2-7 mod 3 · truncated remainder -1 · -7 = 3 x (-3) + 2
Euclidean
2
Remainder
-1
Quotient
-3
Congruence
-7 ≡ 2 (mod 3)
Dividend
Divisor
Headline answer

-7 mod 3 is 2 under the Euclidean convention and -1 as a truncated remainder. The Euclidean modulo answer is 2, with a quotient of -3, since -7 = 3 x (-3) + 2.

Exact integer arithmetic on a 1-digit dividend and a 1-digit divisor: dividend = divisor x quotient + remainder holds exactly on every line below.

Modular inverse

Uses the dividend as a and the absolute value of the divisor as modulus m. A multiplicative inverse exists exactly when gcd(a, m) = 1, for m at least 2.

Multiplicative inverse: 2

Additive inverse: 1

gcd(-7, 3) = 1.

-7 × 2 ≡ 1 (mod 3)

Euclidean algorithm steps

Start with m = 3 and the dividend reduced modulo m. The last nonzero remainder is the gcd; extended Euclid finds the multiplicative inverse when that gcd is 1.

Bézout identity: 1 = (1) × 3 + (-1) × 2. Reducing the dividend coefficient -1 modulo 3 gives inverse 2.

  1. 3 = 1 × 2 + 1; 1 = (1) × 3 + (-1) × 2
  2. 2 = 2 × 1 + 0; 0 = (-2) × 3 + (3) × 2

All three conventions are worked out every time; the buttons choose which result takes the big type. The readout shows Euclidean modulo, the truncated remainder, the selected convention's quotient and the Euclidean congruence. Each box takes a whole number of up to 1,000 digits, and spaces, correctly grouped commas and underscores are read as group separators, so 1,000 and 1 000 are the same number. A caret or double-star power is expanded exactly before the division, so 2^64 is its twenty digits rather than a rounded float. A divisor of 0 is refused, because no remainder exists to show there. The congruence is written with the smallest remainder that is not negative and with the size of the divisor, which is how congruence notation is normally read. Your entry is kept in this browser so the page opens where you left it.

  • -7 and 3truncated, as in C and JavaScript
    -1
  • -7 and 3Euclidean, never negative
    2
  • 2^64 and 9720 digits, BigInt
    61

What each language returns

The same division under all three conventions, worked out for the two numbers above. Every row satisfies dividend = divisor x quotient + remainder; only the rounding of the quotient differs.

ConventionWhere you get itQuotientResult
Truncated remainderThe remainder takes the sign of the dividend.% in C, C++, C#, Java, JavaScript, Go, Rust, Swift and PHP; rem in Haskell and Ada-2-1-7 = 3 x (-2) + (-1)
Floored moduloThe remainder takes the sign of the divisor.% in Python, Ruby and Perl; mod in Haskell; Math.floorMod in Java; MOD in Excel-32-7 = 3 x (-3) + 2
Euclidean moduloThe remainder is never negative.% in Dart; rem_euclid in Rust; mod in ISO Pascal-32-7 = 3 x (-3) + 2
Accuracy. Exact integer arithmetic through BigInt, so a three hundred digit number is not rounded or approximated. Both conventions are printed because they genuinely disagree on negative inputs: the truncated remainder takes the sign of the dividend, the Euclidean modulo is never negative. A zero divisor is refused rather than returned as infinity. The floored convention is listed beside them because it is a third answer rather than a synonym: it agrees with Euclidean for every positive divisor, and can part from it once the divisor goes negative.

Common questions

How do I use this modulo calculator?
Enter the number being divided in Dividend and the modulus in Divisor. Results update as you type. Choose Truncated, Floored or Euclidean to change the headline; all three answers remain in the language table. For 17 and 5, each result is 2 with quotient 3. Copy copies the remainder results and working as text.
How do I find a modular inverse?
Use Dividend for a and Divisor for m, with absolute m at least 2. The Modular inverse section gives both inverses automatically. For 3 modulo 11, the multiplicative inverse is 4 because 3 × 4 ≡ 1 (mod 11); the additive inverse is 8 because 3 + 8 ≡ 0 (mod 11). Open Euclidean algorithm steps for division and Bézout working. A multiplicative inverse exists only when gcd(a, m) = 1; 6 modulo 9 has no multiplicative inverse because the gcd is 3.
What is -7 mod 3?
Euclidean and floored modulo give 2, with quotient -3: -7 = 3 × (-3) + 2. Truncated remainder gives -1, with quotient -2: -7 = 3 × (-2) + (-1). The convention determines which result you need.
Why do Python and JavaScript modulo differ?
For integer operands, Python floors the quotient and its remainder follows the divisor sign. JavaScript truncates the quotient and its remainder follows the dividend sign. The table also labels C#, Java and other listed language conventions. This calculator emulates the integer sign rules; it does not run a language program.
What happens with a negative divisor?
For 7 modulo -3, truncated and Euclidean results are 1, while floored modulo is -2. For -7 modulo -3, truncated and floored results are -1, while Euclidean modulo is 2. Euclidean residues and inverses use the absolute value of the modulus.
Can it calculate powers and large numbers exactly?
Yes, within the 1,000-digit expanded-operand limit. Enter a caret or double-star power such as 2^64 or 2**64 in either box, then open Power expansion steps for the actual repeated-squaring working followed by the modulo division identity. 2^64 = 18446744073709551616, and modulo 97 gives remainder 61 and quotient 190172619316593315. Copy includes the power working and all three modulo identities. Oversized powers are refused; this is a bounded integer-power calculator.
Which input formats are accepted?
Use whole-number digits with an optional sign. Spaces and underscores can group digits; commas must group thousands, such as 1,000. A whole-valued decimal such as 12.0 is accepted, while 12.5, fractions, variables, hexadecimal and binary prefixes are refused. A divisor of 0 returns an error asking for a nonzero divisor.
How do I calculate modulo by hand?
Choose a quotient according to the convention, multiply it by the divisor, then subtract from the dividend: r = a - bq. For 17 and 5, q = 3 and r = 17 - 5 × 3 = 2. Euclidean modulo chooses 0 ≤ r < |b|; truncated division rounds q toward zero and floored division rounds q down.
Does it work on Android, Mac or a computer browser?
Yes. The core calculator works in a current browser without an account or installation. Your edited entries and headline convention are remembered locally. It provides modulo calculations directly; instructions for a named built-in calculator or a specific Casio model are separate device workflows.

Exact integer arithmetic through BigInt, so a three hundred digit number is not rounded or approximated. Both conventions are printed because they genuinely disagree on negative inputs: the truncated remainder takes the sign of the dividend, the Euclidean modulo is never negative. A zero divisor is refused rather than returned as infinity.