Skip to content
Calcipedia

Modular Arithmetic Calculator

Use the modular arithmetic calculator to reduce integers mod n, solve modular addition or multiplication, run modular exponentiation.

Last updated

Number theory worksheet

Modular arithmetic calculator for residues, inverses, powers, and clock arithmetic

Use this modular arithmetic calculator to reduce integers, solve modular addition or multiplication, find a modular inverse, or divide inside a congruence class when an inverse exists. It keeps the remainder non-negative, makes the quotient or inverse explicit, and works for clock arithmetic with modulus 12 or weekday arithmetic with modulus 7.

Exact integer modular arithmetic This page accepts whole integers only. Modular division is only defined when the divisor has an inverse modulo n, so the calculator checks the gcd first instead of returning a misleading number.

Quick examples

Start with a clock-arithmetic remainder, a weekday shift, or an inverse-modulo case, then adjust the integers to your own congruence problem.

Inputs

Enter signed integers for a, b, and the positive modulus n. Use modular inverse for division-style problems when you need to solve b x ≡ a (mod n).

Operation

Find the remainder class of one integer.

Negative integers are allowed. The result is always reported in the standard non-negative residue class when the modulus is positive.

Enter integers Provide value a, a positive modulus n, and value b when the selected modular operation needs it.
← All Number Theory calculators

Number Theory

Modular arithmetic calculator with steps for residues, inverses, powers, and division

Use this modular arithmetic calculator to reduce integers, solve modular addition and multiplication, run a modular exponentiation calculator workflow, or check whether division in modular arithmetic is actually defined. The page keeps the remainder non-negative, shows the relevant congruence class, and explains the quotient, gcd, or inverse so you can audit the result instead of trusting a bare residue.

What a modular arithmetic calculator does

A modular arithmetic calculator works inside a repeating system of residues rather than on the full number line. When you write a ≡ b (mod n), you are saying that a and b leave the same remainder after division by n, or equivalently that their difference is a multiple of n. That is why a modular arithmetic congruence calculator often feels like a remainder tool at first: it reduces an integer into one representative residue class and then keeps future operations inside that cycle.

The practical value is that repeated wraparound problems become easier to read. Clock arithmetic uses modulus 12, weekdays use modulus 7, cyclic buffer positions use the buffer length, and many cryptography and coding problems use much larger moduli. A good modular arithmetic solver should therefore handle more than plain a mod n. It should also support modular addition, subtraction, multiplication, modular exponentiation, and the inverse checks needed before modular division can be trusted.

This page is built as a modular arithmetic calculator with steps, not just a final-answer box. It shows the reduced operands, the resulting congruence class, and the working lines used to justify the answer. That extra structure matters whenever you are checking homework, debugging code, or comparing two methods that ought to land in the same residue class.

a ≡ b (mod n) if and only if n | (a − b)

Two integers are congruent modulo n when their difference is divisible by the modulus.

a = qn + r with 0 ≤ r < n

Modulo reduction writes the dividend as quotient times modulus plus the standard non-negative residue.

Reduction, clock arithmetic, and modular addition

Reduction is the foundation for every other operation on the page. If 17 mod 12 equals 5, then a clock arithmetic calculator reads 17 o'clock as 5 o'clock on a 12-hour cycle. The same idea explains weekday questions. If today is represented by 11 and you add 4 days under modulus 7, the answer wraps to the residue that fits the weekly cycle. That is why clock arithmetic calculator intent belongs naturally under the broader modular arithmetic calculator topic even though the examples feel more concrete.

A modular addition calculator or modular subtraction calculator can reduce each operand before combining them. The identity ((a mod n) + (b mod n)) mod n = (a + b) mod n means you can work with smaller residues without changing the final class. That is especially useful when the original integers are large or negative. The calculator therefore shows the reduced values for a and b as well as the final residue.

One subtle point is sign convention. In programming, remainder semantics for negative numbers vary by language, but in mathematics the standard modulo result for a positive modulus is taken to be non-negative. This page follows that mathematical convention, so -7 mod 3 is reported as 2 rather than -1. That choice makes the congruence class easier to compare across modular addition, modular exponentiation, and inverse-modulo problems.

Modular exponentiation, modular inverse, and division in modular arithmetic

A modular exponentiation calculator computes a^b mod n without expanding the entire power directly. For large exponents, repeated squaring keeps the intermediate values manageable because each multiplication is reduced mod n as the computation proceeds. This is the same broad idea used in many cryptography and number theory workflows, where the exponent may be large but the final answer only depends on the residue class.

Modular inverse is the next key idea. The modular inverse of a is the integer a^-1 such that a × a^-1 ≡ 1 (mod n). An inverse exists only when gcd(a, n) = 1. That gcd test is not optional. If the gcd is greater than 1, there is no multiplicative inverse in that modulus, and a responsible modular inverse calculator should say so plainly instead of outputting a fake result.

That same gcd rule governs division in modular arithmetic. A division in modular arithmetic calculator is really solving a / b mod n by replacing division with multiplication by b^-1 mod n. In other words, a / b mod n means a × b^-1 mod n, provided the inverse exists. If b has no inverse modulo n, the division is undefined in that residue system. This page shows the inverse used when division succeeds and surfaces a warning when gcd(b, n) ≠ 1.

a / b (mod n) = a × b^-1 (mod n)

Modular division is multiplication by the divisor's modular inverse, not ordinary fraction division.

a has an inverse mod n if and only if gcd(a, n) = 1

The extended Euclidean algorithm is the standard way to certify and compute the inverse.

Worked examples: reduction, inverse, and modular division

Start with a plain reduction example. For 29 mod 12, write 29 = 2 × 12 + 5. The quotient is 2 and the residue is 5, so 29 ≡ 5 (mod 12). That is the same reason 29 o'clock on a 12-hour clock becomes 5 o'clock. A modular arithmetic calculator with solution should show both the quotient identity and the congruence because each one verifies the other.

Now take an inverse example: 3^-1 mod 11. We need the integer that multiplies by 3 to give 1 modulo 11. Since 3 × 4 = 12 and 12 ≡ 1 (mod 11), the inverse is 4. The gcd test passes because gcd(3, 11) = 1. That same inverse also drives modular division. To compute 7 / 5 mod 11, first find 5^-1 mod 11. Because 5 × 9 = 45 and 45 ≡ 1 (mod 11), the inverse is 9. Then 7 / 5 mod 11 = 7 × 9 mod 11 = 63 mod 11 = 8.

The contrast case is just as important. Try 4^-1 mod 10. Here gcd(4, 10) = 2, not 1, so no inverse exists and modular division by 4 modulo 10 is undefined. A thin calculator may leave users wondering why the arithmetic 'doesn't work'. A stronger one makes the gcd obstruction visible so the limitation becomes part of the explanation.

What this page covers and what it does not

This worksheet is intentionally scoped to integer modular arithmetic. It accepts signed integers for a and b, requires a positive integer modulus, and uses exact integer operations rather than floating-point arithmetic. That makes it suitable for classroom number theory, discrete mathematics, coding exercises, cryptography examples, and wraparound scheduling problems.

It does not solve arbitrary linear congruence systems, Chinese remainder theorem systems, polynomial congruences, modular roots, or symbolic proofs. It also does not accept fractional exponents or non-integer inputs. If your task depends on those extensions, treat this calculator as a residue and inverse worksheet rather than a complete computer algebra system.

The page also keeps 'clock arithmetic calculator' as supporting coverage rather than changing the underlying scope. Clock time and weekdays are useful illustrations of modular arithmetic, but the primary intent here is still the broader modular arithmetic calculator: a tool for congruence classes, modular exponentiation, modular inverse, and division inside a modulus.

Frequently asked questions

What is the difference between modulo and remainder?

For positive numbers the two often match, but for negative dividends or divisors the conventions can differ. This calculator follows the standard mathematical modulo convention for a positive modulus, so the answer is always reported as a non-negative residue between 0 and n - 1.

Why does modular division sometimes fail?

Because modular division is only shorthand for multiplying by a modular inverse. The divisor b must satisfy gcd(b, n) = 1 so that b^-1 exists modulo n. If the gcd is greater than 1, there is no valid inverse and the division is undefined in that modulus.

How does the modular inverse calculator find the answer?

It uses the extended Euclidean algorithm idea: find integers x and y such that ax + ny = gcd(a, n). When the gcd is 1, the coefficient x is an inverse of a modulo n after reduction back into the standard residue class.

Is clock arithmetic the same thing as modular arithmetic?

Clock arithmetic is a special case of modular arithmetic. A 12-hour clock uses modulus 12 and weekdays use modulus 7. The same congruence rules apply; the setting is just more familiar than an abstract residue class.

What does the quotient mean in a mod n?

The quotient is the integer q in the identity a = qn + r. It tells you how many full modulus-length cycles fit into a before the remaining residue r is left over. Showing q makes the remainder calculation easier to verify by hand.

Why is modular exponentiation important in cryptography?

Many public-key and discrete-math workflows rely on raising integers to large powers while reducing modulo a chosen n. The repeated-squaring approach makes that practical because the intermediate values are reduced along the way instead of growing uncontrollably.

Can this modular arithmetic calculator solve negative-number examples?

Yes. You can enter negative integers for a or b, and the page will reduce them into the standard non-negative residue class for the selected positive modulus. That makes it useful for congruence checks that begin with signed values.

Does this page solve the Chinese remainder theorem or systems of congruences?

No. This page is scoped to one modulus at a time. It is designed for residue reduction, modular addition or multiplication, modular inverse, modular division, and modular exponentiation inside a single congruence system.

Also in Number Theory

Related

More from nearby categories

These related calculators come from the same leaf category, nearby sibling categories, or the same top-level topic.