Pick an operation in the Operation dropdown. Thirteen are listed, from basic modulo to GCD and coprime checks; the boxes below change to two or three. Learn more about the operations
Type the numbers: First Number (a), then the Modulus (m) or Second Number (b), and for three-number operations the modulus in the third box. Whole numbers, negatives and decimals are accepted. Learn more about the inputs
Click Calculate. The result appears in the blue box under the buttons; a red message appears instead when a number is missing, the modulus is zero, or an inverse does not exist. Learn more about the results
The panel on the right explains the chosen operation with a definition and an example, and its link opens the section below that explains it in full. Learn more about the panel
Select an operation from the dropdown menu to begin. The calculator offers 13 different modular arithmetic operations, from basic modulo to advanced cryptographic functions. The interface automatically adjusts based on your selection, showing either two or three input fields depending on the operation's requirements.
Enter your numbers in the input fields. The calculator accepts integers, negative numbers, and decimal values. For basic modulo operations like amodb, you'll enter two values. For operations like modular addition (a+b)modm, you'll enter three values including the modulus.
Click the Calculate button to compute your result. The answer appears in a highlighted box below the inputs, and the right panel updates with a detailed explanation of the operation including mathematical definitions and concrete examples. If you encounter an error, the calculator displays a clear message in red explaining the issue.
Use the Reset button to clear all inputs and start fresh with new calculations. The operation type remains selected, allowing you to quickly try different values with the same operation. A first example to try is 17mod5=2; what the remainder means is explained in what is modular arithmetic.
Understanding the 13 Operation Types
DemoTwo-number and three-number operations
Step 0 of 4
The calculator provides thirteen distinct operations covering the full spectrum of modular arithmetic. Basic Modulo computes the remainder amodb, the foundation of all modular operations. Negative Number Modulo demonstrates proper handling of negative inputs to ensure results stay within [0,m−1].
Decimal/Float Modulo extends operations to non-integer values using the formula a−b×⌊a/b⌋. The arithmetic operations—Modular Addition, Subtraction, and Multiplication—perform standard calculations while keeping results within modular bounds.
Modular Division finds (a×b−1)modm where b−1 is the multiplicative inverse. Modular Exponentiation computes abmodm efficiently using fast algorithms. Modular Inverse finds a−1 such that (a×a−1)modm=1.
Congruence Check verifies if a≡b(modm). GCD and LCM calculate the greatest common divisor and least common multiple. Coprime Check determines if two numbers share only 1 as a common factor. Each operation includes educational content explaining theory and applications. Operations on three numbers show a third box for the modulus: Modular Addition, for example, computes (8+7)mod10=5. Which operation fits which problem is discussed in when to use each operation.
Working with Different Number Types
DemoNegative and decimal inputs
Step 0 of 5
The calculator handles three types of numerical inputs seamlessly. Integer operations accept whole numbers and provide exact results for all thirteen operation types. Enter values like 17, 42, or 100 directly.
Negative numbers require special handling in modular arithmetic. When you enter −7 with modulus 5, the calculator applies the formula ((amodb)+b)modb to ensure the result falls within [0,4]. The "Negative Number Handling" operation provides detailed explanations of this adjustment process.
Decimal numbers work with most operations, though GCD, LCM, and coprime checks require integers. For float modulo, the calculator uses a−b×⌊a/b⌋ to compute remainders with fractional values, for example 7.5mod2=1.5. This is useful for wrapping coordinates in graphics or handling periodic functions with non-integer periods. How negative inputs are reduced is explained in negative number modulo.
The calculator processes large numbers up to JavaScript's numerical limits. For operations involving very large numbers (common in cryptography), consider the efficiency of modular exponentiation, which avoids computing massive intermediate values.
Reading and Interpreting Results
DemoA result and an error message
Step 0 of 5
Results appear in the blue-highlighted box immediately after calculation. For simple operations like basic modulo, you'll see a single numerical answer. For operations like congruence checking, you'll see a statement confirming whether a≡b(modm) or a≡b(modm).
The right panel updates simultaneously with each calculation, displaying the operation's title, mathematical definition, and a concrete example. This contextual information helps you understand not just the answer, but the underlying mathematics.
Error messages appear in red when something goes wrong. Common errors include division by zero (when modulus is 0), attempting modular division when numbers aren't coprime, or using non-integers for operations that require whole numbers. Each error message explains exactly what went wrong and how to fix it.
For modular inverse operations, if no inverse exists, the calculator clearly states that the numbers aren't coprime and no unique solution is available: the inverse of 3 modulo 10 is 7, while 4 has no inverse modulo 10. This immediate feedback helps you understand the mathematical constraints of each operation. The condition is explained in modular inverse.
Exploring Modular Arithmetic Operations
DemoModular addition and subtraction
Step 0 of 5
Experiment with the four basic arithmetic operations under modular constraints. Try modular addition: compute (8+7)mod10=5, observing how results wrap around like clock arithmetic. Compare this to regular addition where 8+7=15.
Test modular subtraction with examples where results would be negative: (3−7)mod10=6. Switching from addition to subtraction keeps your numbers, so 8, 7 and 10 give (8−7)mod10=1. The calculator automatically adjusts negative results to the proper range, demonstrating how modular arithmetic maintains consistency. The rules are proved in modular addition.
Explore modular multiplication with larger numbers. Calculate (6×7)mod10=2 and observe how even large products reduce to values within [0,9]. This property prevents overflow in computer arithmetic.
Try modular division, but note it requires coprime numbers. Attempt 8÷3mod10 (which works) versus 8÷4mod10 (which fails because 4 and 10 aren't coprime). Understanding when division is possible is crucial for cryptographic applications.
Using Advanced Cryptographic Operations
DemoModular exponentiation and a coprime check
Step 0 of 5
Modular exponentiation is essential for cryptography. Calculate 413mod497=445 and observe how the calculator handles this efficiently without computing 413=67,108,864 first. The fast exponentiation algorithm applies modular reduction at each step, keeping numbers manageable.
Explore modular multiplicative inverses, the foundation of RSA encryption. Find the inverse of 3mod10, which is 7 because (3×7)mod10=1. Try finding inverses for different values and observe when they exist (only when numbers are coprime).
Test the coprime checker to verify relationships before attempting division or finding inverses. Check if 25 and 36 are coprime (they are, with GCD=1), then verify if 12 and 18 are coprime (they aren't, with GCD=6); 4 and 13 are coprime too. The fast method is explained in modular exponentiation.
Practice with congruence checking to verify equivalences: confirm that 17≡2(mod5) because both leave remainder 2 when divided by 5. This operation helps verify solutions to modular equations.
What is Modular Arithmetic
Modular arithmetic is a system where numbers wrap around after reaching a certain value called the modulus. Think of a 12-hour clock: after 12 comes 1, not 13. Mathematically, we say 13≡1(mod12) because both leave the same remainder when divided by 12.
The modulo operation amodm finds the remainder when a is divided by m. This remainder always falls within [0,m−1]. For example, 17mod5=2 because 17=5×3+2.
Modular arithmetic appears throughout mathematics and computer science. In cryptography, it forms the basis of RSA encryption. In programming, it handles cyclic structures, array indexing with wraparound, and hash table implementations. Understanding modular arithmetic is essential for computer science, cryptography, and advanced mathematics.
A negative dividend still leaves a remainder in the range [0,m−1], but a calculator or a programming language may report a different value. This calculator uses the floored convention: −7mod5=3, because −7=5×(−2)+3. Each step down by one lowers the remainder by one and wraps: −1mod5=4, −10mod5=0.
To compute it by hand, take the remainder as if the sign were absent, then subtract it from the modulus: 7mod5=2, so −7mod5=5−2=3. When the first remainder is 0 the answer stays 0. The calculator applies ((amodb)+b)modb, which gives the same result and never returns a negative number.
The common mistake is to answer −2, which is what truncated division gives: −7=5×(−1)−2. Both conventions agree on positive numbers and differ only for negative ones, so always say which one you mean.
The modulo operation extends to decimals with the same idea: subtract the largest whole-number multiple of the divisor that fits, and keep what is left. The formula is a−b×⌊a/b⌋, where ⌊x⌋ rounds down. For 7.5mod2: 7.5/2=3.75, round down to 3, and 7.5−2×3=1.5. For 5.5mod1.5: 5.5/1.5≈3.67, round down to 3, and 5.5−1.5×3=1.
Decimal modulo is used for anything that repeats with a non-integer period: an angle reduced to [0,360), a time of day in hours, or a wave with period 2π.
The common mistake is a rounding surprise: a computer stores most decimals approximately, so the raw result of 7.5mod2.2 is 0.8999999999999995 rather than 0.9. The calculator rounds the result to twelve significant digits, so it shows 0.9; when you compute by hand or in code, read such a result as 0.9, since the difference is floating-point error, not mathematics.
Modular addition adds two numbers and reduces the sum: (a+b)modm. It is clock arithmetic: on a clock with m hours, moving b hours past a lands on (a+b)modm.
Example: (8+7)mod10. First 8+7=15, then 15mod10=5. On a 12-hour clock, (23+19)mod12=42mod12=6: 19 hours after 23 o'clock is 6 o'clock.
The numbers can be reduced before adding without changing the answer: (amodm+bmodm)modm gives the same result, which keeps the arithmetic small when a and b are large. The common mistake is to forget the final reduction and report 15 instead of 5; the result must lie in [0,m−1].
Modular subtraction computes (a−b)modm and, when the difference is negative, adds the modulus to bring it back into [0,m−1].
Example: (3−7)mod10. The difference is −4; adding 10 gives 6, so the answer is 6. On a 12-hour clock, 9 hours before 2 o'clock is (2−9)mod12=−7+12=5 o'clock. The calculator computes ((a−b)modm+m)modm, which handles both signs.
A check: 6+7=13 and 13mod10=3, the number we started from, so subtracting 7 really did undo adding 7. The common mistake is to stop at −4: a negative value is not a valid remainder.
Modular multiplication computes (a×b)modm: multiply, then take the remainder.
Example: (6×7)mod10=42mod10=2. With a prime modulus: (13×17)mod11=221mod11=1, since 221=11×20+1. The factors may be reduced first: 13mod11=2 and 17mod11=6, and (2×6)mod11=12mod11=1, the same answer with smaller numbers.
Reducing first matters in practice: multiplying very large numbers directly overflows a computer's integers, while (amodm)×(bmodm) stays small. The common mistake is to reduce the factors and forget the product; the final result always needs one more reduction.
Division modulo m is not a division at all: a÷bmodm means (a×b−1)modm, where b−1 is the number whose product with b leaves remainder 1. Such a number exists only when b and m are coprime.
Example: 8÷3mod10. The inverse of 3 modulo 10 is 7, because 3×7=21 and 21mod10=1. Then 8×7=56 and 56mod10=6. Check: 6×3=18 and 18mod10=8, the number we divided.
8÷4mod10 has no single answer: both x=2 and x=7 give 4xmod10=8, because 4 and 10 share the factor 2. The calculator reports that 4 has no modular inverse modulo 10. The common mistake is to divide normally and reduce: 8÷4=2 is one of two answers here, and 8÷3 is not even a whole number.
Modular exponentiation computes abmodm without ever forming ab. The trick is to reduce after every multiplication, because (x×y)modm depends only on xmodm and ymodm.
Small example: 34mod5. 32=9≡4, then 34=(32)2≡42=16≡1(mod5). Larger example: 413mod497=445, which the calculator finds by squaring and reducing, never touching 413=67108864. Also 210mod7=1024mod7=2.
The square-and-multiply method reads the exponent in binary: square the running value for each bit, multiply by the base for each bit that is 1, and reduce each time. It needs about 2log2b multiplications instead of b. The common mistake is to compute the full power first; at cryptographic sizes it fits in no computer. The exponent here must be a non-negative integer.
The modular inverse of a modulo m is the number x in [0,m−1] with (a×x)modm=1. It plays the role of 1/a in modular arithmetic and exists exactly when gcd(a,m)=1.
Example: the inverse of 3 modulo 10 is 7, since 3×7=21 and 21mod10=1. The inverse of 7 modulo 26 is 15, since 7×15=105=4×26+1. The number 4 has no inverse modulo 10: every multiple of 4 is even, so none of them leaves remainder 1 when divided by 10.
By hand, the extended Euclidean algorithm writes gcd(a,m)=1 as ax+my=1; then xmodm is the inverse. For a small modulus, trying x=1,2,3,… until axmodm=1 is quicker. The common mistake is to expect an inverse for every number; the calculator says when there is none.
Two numbers are congruent modulo m when they leave the same remainder on division by m, written a≡b(modm). Equivalently, m divides a−b.
Example: 17≡2(mod5), because 17mod5=2 and 2mod5=2; also 17−2=15 is a multiple of 5. Likewise 14≡23(mod9), since both leave remainder 5. But 17≡3(mod5): the remainders are 2 and 3.
The calculator reduces both numbers with the floored rule, so negative inputs work: −7≡3(mod5). Congruence is what makes modular arithmetic consistent: congruent numbers can replace each other in sums and products without changing the result modulo m. The common mistake is to compare a with b directly instead of comparing amodm with bmodm; the modulus is the third number.
The Greatest Common Divisor (GCD) of two integers is the largest number that divides both without remainder. For GCD(48,18)=6 because 6 is the largest number dividing both 48=6×8 and 18=6×3. The Euclidean algorithm computes GCD efficiently through repeated division.
The Least Common Multiple (LCM) is the smallest positive integer divisible by both numbers. For LCM(4,6)=12 because 12 is the smallest number where both 4 and 6 divide evenly. The relationship LCM(a,b)=GCD(a,b)a×b connects these concepts.
These functions are fundamental to modular arithmetic. GCD determines if numbers are coprime (when GCD=1), which controls whether modular inverses exist. LCM appears in problems involving periodic cycles, fraction arithmetic, and scheduling when multiple cycles must align.
The greatest common divisor of two integers is the largest positive integer that divides both. gcd(48,18)=6: the divisors of 18 are 1,2,3,6,9,18, and 6 is the largest of them that also divides 48.
The Euclidean algorithm finds it without listing divisors: divide and keep the remainder until the remainder is 0; the last non-zero remainder is the GCD. For 48 and 18: 48=2×18+12, 18=1×12+6, 12=2×6+0, so the GCD is 6. Each line is a modulo operation, which is why the GCD belongs in this calculator.
gcd(a,b)=1 means the numbers are coprime; that is the test behind modular division and inverses. The common mistake is to stop at any common divisor: 2 and 3 divide both 48 and 18, but the greatest one is 6. The calculator takes absolute values, so negative inputs give the same GCD.
The least common multiple of two integers is the smallest positive integer that both divide. lcm(4,6)=12: the multiples of 6 are 6,12,18,…, and 12 is the first that is also a multiple of 4.
The quickest method uses the GCD: lcm(a,b)=gcd(a,b)a×b. For 48 and 18: gcd=6, so lcm=648×18=6864=144. For 4 and 6: gcd=2 and 224=12. When the numbers are coprime the LCM is simply their product.
The LCM is the common denominator for adding fractions and the first moment two repeating cycles coincide: two lights blinking every 4 and every 6 seconds blink together every 12 seconds. The common mistake is to take the product a×b as the LCM; it is a common multiple but not the least one unless the numbers are coprime.
Two numbers are coprime (relatively prime) when their only common factor is 1, meaning GCD(a,m)=1. For example, 25 and 36 are coprime despite both being composite, because they share no prime factors: 25=52 and 36=22×32.
Coprimality determines when modular division and inverses exist. The number a has a multiplicative inverse modulo m if and only if a and m are coprime. This is why 3 has an inverse mod 10 (they're coprime), but 4 doesn't have an inverse mod 10 (they share factor 2).
In cryptography, choosing coprime numbers ensures key generation succeeds. Understanding coprimality is essential for working with modular division and inverse operations in this calculator. The Check if Coprime operation runs this test. See coprime numbers and properties of coprime numbers.
Common Mistakes and How to Avoid Them
Forgetting the modulus cannot be zero is the most common error. Division by zero is undefined, so always ensure your modulus is at least 1. The calculator will alert you with an error message if you try this.
Expecting modular division to always work leads to confusion. Remember that modular division only works when the divisor and modulus are coprime. Check the GCD first—if it's not 1, division won't have a unique solution.
Mishandling negative numbers causes incorrect results. In modular arithmetic, −7mod5 should give 3, not −2. The calculator automatically handles this, but when doing manual calculations, remember to add the modulus to negative remainders.
Using decimals for GCD and LCM won't work because these operations require integers. The calculator will reject decimal inputs for these specific operations. If you need to work with decimals, use the float modulo operation instead. More pitfalls with negative numbers are listed in common pitfalls.
Practical Tips for Using This Calculator
Start simple with basic modulo operations before moving to advanced functions. Try 17mod5 to understand remainders, then progress to modular addition and multiplication.
Use the right panel explanations as learning tools. Each time you calculate, read the explanation to understand the mathematical principles behind the operation. The examples shown match the type of calculation you're performing.
Verify your homework by first calculating manually, then checking your answer with the calculator. This helps you learn the concepts while ensuring accuracy. The detailed explanations can also help you understand where you went wrong if answers don't match.
Experiment with different values to see patterns. Try the same operation with various moduli to observe how results change. Notice how modular addition with modulus 10 behaves like a clock counting from 0 to 9. Worked problems to practise with are in worked examples.
When to Use Each Operation
Use Basic Modulo for finding simple remainders in division problems, checking if numbers are divisible, or working with cyclic patterns. This is your starting point for all modular arithmetic.
Choose Modular Addition, Subtraction, or Multiplication when performing arithmetic that needs to stay within bounds, such as clock calculations, circular buffer indexing, or preventing integer overflow in programming.
Select Modular Division or Inverse when solving equations in cryptography, implementing encryption algorithms, or working with fraction arithmetic in modular systems. Remember these only work with coprime numbers.
Pick GCD and LCM for simplifying fractions, finding common denominators, or determining if modular inverses exist. Use Coprime Check before attempting division or inverse operations to avoid errors. The operations are summarised in the operations toolkit, and the uses of modulo in why modulo matters.