Modular Addition Calculator
Enter two numbers and a modulus to compute (a + b) mod m.
Result
How it is calculated
The tool adds the two numbers and wraps the sum into the range 0 to m − 1: sum = a + b, then result = ((sum mod m) + m) mod m. The second step matters for negative sums: a plain remainder in programming can be negative, but this tool always gives the mathematical answer between 0 and m − 1. The modulus m must be a whole number of at least 1, and a and b must be whole numbers too, though they may be zero or negative. A decimal such as 2.5 or 7.5 returns no result rather than being rounded, as does a modulus below 1. Values beyond about 9 × 1015 (253) are also rejected, so no digits are silently lost. The tool shows three values: the result, the ordinary sum, and the modulus. With m = 1 every result is 0.
Worked example
Take a = 47, b = −38 and m = 12. The ordinary sum is 47 + (−38) = 9. Dividing by 12 gives remainder 9, which is already in the range 0 to 11, so the result is 9. Now try a = −7, b = 3, m = 5: the sum is −4, and −4 + 5 = 1, so the result is 1 (not −4). A clock is the everyday case: 10 o'clock plus 5 hours is the sum 15, and 15 mod 12 = 3, so 3 o'clock.
Common mistakes
- Expecting a negative remainder for a negative sum. Here −4 mod 5 is 1, because the result is always from 0 to m − 1.
- Entering a decimal such as 7.5 and expecting it to be rounded. Modular addition is defined for integers, so a decimal in a or b gives no result.
- Using m = 0, a negative modulus or a decimal modulus; the modulus must be a whole number of at least 1.
- Mixing up the sum with the result. The "sum" line is the ordinary a + b; the answer to the problem is the "result" line.
- Treating modulus 12 as giving 0 to 12 on a clock. The results run 0 to 11, so a clock showing 12 corresponds to 0.
About this calculator
Modular addition computes (a + b) mod m — the remainder left after dividing the ordinary sum a + b by the modulus m — and always returns a normalized result in the range 0 to m−1, no matter how large or negative a and b are. It follows the familiar rule of "wrapping around" once the sum reaches m, exactly like a clock face wraps from 12 back to 1.
This operation is the basis of modular arithmetic, taught alongside congruences in number theory, and it underlies practical systems from clock and calendar arithmetic to cyclic redundancy checks, hash table indexing, and cryptographic algorithms such as RSA and elliptic-curve schemes, where all arithmetic is deliberately confined to a fixed modulus.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
Weekday arithmetic is an easy real use. Number the days with Monday as 0, so Thursday is 3. Adding 45 days and using modulus 7 gives 6 (sum 48), which is Sunday. The same trick works for any cyclic count: hours with modulus 24, or array positions in a circular buffer. Remember that the tool only accepts whole numbers. What cycle are you wrapping around: dates, hash buckets, something from a number theory course?