Bookmarks    
nPr and nCr    
Random Number    
SD Calculator    
Sample Size    
Percent Error    
Density    
Molarity    
Molar Mass    
Ohm's Law    
Watts to Amps    
Voltage Drop    
Long Division    
Mixed Numbers    
Rounding    
Nth Root    
Exponents    
Half-Life    
Polar Form    
De Moivre    
3D Distance    
Point to Line    
Cross Product    
Determinant    
Sin Cos Tan    
Triangle Area    
Scale Factor    
Sector Area    
Ellipse Area    
Cube Volume    
Box Volume    
Sphere Volume    
Cone Volume    
Pipe Volume    
Time Duration    
Time Card    
Present Value    
Future Value    
Churn Rate    
A/B Test Calc    
SEO Traffic    
Ideal Weight    
Fat Intake    
Child Height    
Golf Handicap    
Heat Index    
Wind Chill    
Dew Point    
Download Time    
kWh to Cost    
AC Size (BTU)    
Heating Costs    
LED Savings    
Trip Gas Cost    
Tire Size    
Solar Output    
Solar Payback    
Battery Size    
Wall Area    
Gravel Needed    
Mortar Mix    
Slope Grade    
Curtain Size    
Soil Needed    
Sod Needed    
Ramp Length    
Blind Size    
Drain Slope    
Board Feet    
Heat Loss    
Furniture Fit    
Moving Boxes    
Plywood Cuts    
Shelf Sag    
   Add
Probability and random number calculators
Independent Events
Independent Events
Two Events Solver
Two Events Solver
Repeated Trials
Repeated Trials
Bayes' Theorem
Bayes' Theorem
Expected Value
Expected Value
Binomial Distribution
Binomial Distribution
nPr and nCr
nPr and nCr
Circular Permutation
Circular Permutation
With Repetition
With Repetition
Random Number
Random Number
Averages and statistics calculators
Average Calculator
Average Calculator
Mean Median Mode
Mean Median Mode
SD Calculator
SD Calculator
Quartiles & IQR
Quartiles & IQR
Frequency Table
Frequency Table
Correlation (r)
Correlation (r)
Normal Probability
Normal Probability
Z-Score Calculator
Z-Score Calculator
Confidence Interval
Confidence Interval
Sample Size
Sample Size
Mark & Recapture
Mark & Recapture
P-Value Calculator
P-Value Calculator
Percentage and ratio calculators
Percentage Calc
Percentage Calc
Percent Change
Percent Change
Percent Difference
Percent Difference
Percent Error
Percent Error
Ratio Calculator
Ratio Calculator
Discount Calculator
Discount Calculator
Sales Tax Calculator
Sales Tax Calculator
Margin Calculator
Margin Calculator
Speed calculators
Speed Calculator
Speed Calculator
Density and concentration calculators
Density
Density
Molarity
Molarity
Molar Mass
Molar Mass
Physics and electricity calculators
Ohm's Law
Ohm's Law
Watts to Amps
Watts to Amps
Resistor Colors
Resistor Colors
Voltage Drop
Voltage Drop
Unit conversion calculators
Weight Converter
Weight Converter
Shoe Size Converter
Shoe Size Converter
Integer and signed number calculators
Long Division
Long Division
LCM Calculator
LCM Calculator
GCF Calculator
GCF Calculator
Integer Calculator
Integer Calculator
Prime Factorization
Prime Factorization
Diophantine Solver
Diophantine Solver
Modulo Calculator
Modulo Calculator
Factor Calculator
Factor Calculator
Roman Numerals
Roman Numerals
Fraction, decimal and rounding calculators
Fraction Calculator
Fraction Calculator
Mixed Numbers
Mixed Numbers
Simplify Fractions
Simplify Fractions
Fraction to Decimal
Fraction to Decimal
Decimal to Fraction
Decimal to Fraction
Rounding
Rounding
Equation and inequality calculators
Linear Equation
Linear Equation
Linear Systems
Linear Systems
Quadratic Formula
Quadratic Formula
Absolute Value
Absolute Value
Quadratic Inequality
Quadratic Inequality
Polynomial calculators
Binomial Theorem
Binomial Theorem
Square root and nth root calculators
Simplify Radicals
Simplify Radicals
Nth Root
Nth Root
Exponent and logarithm calculators
Exponents
Exponents
Log Calculator
Log Calculator
Number of Digits
Number of Digits
Scientific Notation
Scientific Notation
Sci. Notation Math
Sci. Notation Math
Half-Life
Half-Life
Complex number calculators
Complex Numbers
Complex Numbers
Polar Form
Polar Form
De Moivre
De Moivre
Function and graph calculators
Slope Calculator
Slope Calculator
Linear Function
Linear Function
Direct & Inverse Variation
Direct & Inverse Variation
y = ax² Calculator
y = ax² Calculator
Distance Formula
Distance Formula
3D Distance
3D Distance
Section Formula
Section Formula
Point to Line
Point to Line
Lat/Long Distance
Lat/Long Distance
Complete the Square
Complete the Square
Circle Equation
Circle Equation
Conic Sections
Conic Sections
Polar Coordinates
Polar Coordinates
Sequence calculators
Arithmetic Sequence
Arithmetic Sequence
Geometric Sequence
Geometric Sequence
Fibonacci Sequence
Fibonacci Sequence
Recurrence Relation
Recurrence Relation
Vector calculators
Vector Calculator
Vector Calculator
Cross Product
Cross Product
Matrix calculators
Matrix Calculator
Matrix Calculator
Determinant
Determinant
Inverse Matrix
Inverse Matrix
Plane geometry calculators
Sin Cos Tan
Sin Cos Tan
Degrees ⇔ Radians
Degrees ⇔ Radians
a sin θ + b cos θ
a sin θ + b cos θ
Triangle Solver
Triangle Solver
Triangle Area
Triangle Area
Right Triangle
Right Triangle
Pythagorean Theorem
Pythagorean Theorem
Polygon Angles
Polygon Angles
Scale Factor
Scale Factor
Parallel Lines
Parallel Lines
Rectangle Area
Rectangle Area
Parallelogram Area
Parallelogram Area
Trapezoid Area
Trapezoid Area
Circle Calculator
Circle Calculator
Sector Area
Sector Area
Inscribed Angle
Inscribed Angle
Ellipse Area
Ellipse Area
Solid geometry calculators
Cube Volume
Cube Volume
Cube Surface Area
Cube Surface Area
Box Volume
Box Volume
Box Surface Area
Box Surface Area
Cylinder Volume
Cylinder Volume
Cylinder Surface
Cylinder Surface
Sphere Volume
Sphere Volume
Sphere Surface
Sphere Surface
Spherical Cap Volume
Spherical Cap Volume
Cap Surface Area
Cap Surface Area
Ellipsoid Volume
Ellipsoid Volume
Ellipsoid Surface
Ellipsoid Surface
Pyramid Volume
Pyramid Volume
Pyramid Surface
Pyramid Surface
Cone Volume
Cone Volume
Cone Surface Area
Cone Surface Area
Frustum Volume
Frustum Volume
Frustum Surface Area
Frustum Surface Area
Pipe Volume
Pipe Volume
Capsule Volume
Capsule Volume
Capsule Surface Area
Capsule Surface Area
Date and time calculators
Age Calculator
Age Calculator
Days Between Dates
Days Between Dates
Date Calculator
Date Calculator
Hours From Now
Hours From Now
Day of the Week
Day of the Week
Time Calculator
Time Calculator
Time Zone Converter
Time Zone Converter
Hours Calculator
Hours Calculator
Time Duration
Time Duration
Time Card
Time Card
Finance and economics calculators
Compound Interest
Compound Interest
Simple Interest
Simple Interest
Interest Calculator
Interest Calculator
TVM Calculator
TVM Calculator
Present Value
Present Value
Future Value
Future Value
ROI Calculator
ROI Calculator
IRR Calculator
IRR Calculator
Payback Period
Payback Period
Average Return
Average Return
GDP Calculator
GDP Calculator
Web marketing and ad metric calculators
CTR Calculator
CTR Calculator
Conversion Rate
Conversion Rate
CPC, CPM & CPA
CPC, CPM & CPA
ROAS Calculator
ROAS Calculator
Break-Even CPA
Break-Even CPA
LTV Calculator
LTV Calculator
CAC Calculator
CAC Calculator
Churn Rate
Churn Rate
A/B Test Calc
A/B Test Calc
A/B Sample Size
A/B Sample Size
SEO Traffic
SEO Traffic
Break-Even Point
Break-Even Point
Markup vs. Margin
Markup vs. Margin
CAGR Calculator
CAGR Calculator
Health and fitness calculators
BMI Calculator
BMI Calculator
Sleep Calculator
Sleep Calculator
Calorie Calculator
Calorie Calculator
BMR Calculator
BMR Calculator
TDEE Calculator
TDEE Calculator
Ideal Weight
Ideal Weight
Body Fat Calculator
Body Fat Calculator
Lean Body Mass
Lean Body Mass
Calories Burned
Calories Burned
Protein Intake
Protein Intake
Macro Calculator
Macro Calculator
Carb Calculator
Carb Calculator
Fat Intake
Fat Intake
Child Height
Child Height
Sports calculators
Golf Handicap
Golf Handicap
Pace Calculator
Pace Calculator
1RM Calculator
1RM Calculator
Target Heart Rate
Target Heart Rate
Weather calculators
Heat Index
Heat Index
Wind Chill
Wind Chill
Dew Point
Dew Point
Computer calculators
Base Converter
Base Converter
Subnet Calculator
Subnet Calculator
Download Time
Download Time
Household energy and budget calculators
Electricity Cost
Electricity Cost
kWh to Cost
kWh to Cost
Yearly kWh to Cost
Yearly kWh to Cost
AC Size (BTU)
AC Size (BTU)
AC Running Cost
AC Running Cost
Heating Costs
Heating Costs
Gas vs Electric
Gas vs Electric
LED Savings
LED Savings
Salary Calculator
Salary Calculator
Budget Calculator
Budget Calculator
Car calculators
Trip Gas Cost
Trip Gas Cost
EV Charging Cost
EV Charging Cost
EV vs Gas Cost
EV vs Gas Cost
MPG Calculator
MPG Calculator
Tire Size
Tire Size
Solar power and battery calculators
Solar Output
Solar Output
Solar Panel Count
Solar Panel Count
Solar Payback
Solar Payback
Battery Size
Battery Size
Home and DIY calculators
Tile Calculator
Tile Calculator
Stair Calculator
Stair Calculator
Concrete Volume
Concrete Volume
Wall Area
Wall Area
Wallpaper Rolls
Wallpaper Rolls
Paint Calculator
Paint Calculator
Flooring Needed
Flooring Needed
Exterior Walls
Exterior Walls
Gravel Needed
Gravel Needed
Mortar Mix
Mortar Mix
Slope Grade
Slope Grade
Lumber Cut List
Lumber Cut List
Lot Coverage/FAR
Lot Coverage/FAR
Sheet Vinyl Roll
Sheet Vinyl Roll
Insulation Needed
Insulation Needed
Curtain Size
Curtain Size
TV Size & Distance
TV Size & Distance
Soil Needed
Soil Needed
Sod Needed
Sod Needed
Block Calculator
Block Calculator
Brick Calculator
Brick Calculator
Deck Materials
Deck Materials
Ramp Length
Ramp Length
Pilot Hole Size
Pilot Hole Size
Room Ventilation
Room Ventilation
Paint Thinning
Paint Thinning
Baseboard & Trim
Baseboard & Trim
Blind Size
Blind Size
Picture Hanging
Picture Hanging
Drain Slope
Drain Slope
Screw Calculator
Screw Calculator
Board Feet
Board Feet
Fence Calculator
Fence Calculator
Wood Shrinkage
Wood Shrinkage
Caulk Calculator
Caulk Calculator
Heat Loss
Heat Loss
Furniture Fit
Furniture Fit
Moving Boxes
Moving Boxes
Storage Capacity
Storage Capacity
Plywood Cuts
Plywood Cuts
Shelf Sag
Shelf Sag

Modulo Calculator (a mod n, Congruence and Modular Exponentiation)

Choose a mode and enter integers. "Remainder" also works with negative numbers and shows how the math remainder (0 or more) differs from the % operator in programming.

Enter whole numbers only (no decimals or fractions). a, b and n can have up to 30 digits, the exponent k is 0 or more with up to 9 digits, and the modulus n is 1 or more.
Result and figure
Choose a mode on the left, enter integers and press "Calculate". The result will appear here (when the modulus n is 2 to 24, a clock diagram also shows where the remainder lands).

What you can do on this page

  • Find the remainder when an integer \(a\) is divided by \(n\). Negative numbers work too (for example, \(-7\) divided by \(3\)): the page shows the math remainder (\(0 \le r < n\)) side by side with the result of the % operator in C, Java, JavaScript and similar languages (which can be negative)
  • Check whether the congruence \(a \equiv b \pmod{n}\) holds, with the reason: whether the difference \(a - b\) is a multiple of \(n\)
  • Get the exact remainder of a huge power, such as \(7^{100}\) divided by \(13\), with the steps of repeated squaring (numbers too big for a regular calculator are no problem)
  • See the remainder on a clock diagram (the circle of mod \(n\)) and get a feel for how remainders go around and around the same positions (the clock appears when the modulus \(n\) is 2 to 24)
  • A plain-language explanation of the formulas and copy-and-paste formulas for Excel, Google Sheets and Python are all on this page
The modulus \(n\) is an integer of 1 or more. Enter \(a\), \(b\) and \(n\) with up to 30 digits, and the exponent \(k\) as an integer of 0 or more with up to 9 digits.

What is this calculation used for?

Clock and calendar math (what day of the week is it in N days?)

On a clock, "14:00 is 2 p.m." is exactly the remainder calculation 14 mod 12 = 2. Days of the week work the same way, on a clock that goes around once every 7 days. For example, if today is Monday, then since 100 mod 7 = 2, the day 100 days from now is "2 days after Monday", which is Wednesday.
Paper planners and calendar apps alike match dates to days of the week with this remainder calculation.

Check digits that catch wrong numbers (barcodes and ISBNs)

The last digit of a product barcode (UPC) or a book's ISBN is a check digit made from the other digits with a remainder calculation. For a UPC, for example, the digits are multiplied alternately by 3 and 1 and added up, and the last digit is chosen from the remainder of that total divided by 10.
If one digit is mistyped, the remainder no longer matches, so checkout registers and online stores can catch the mistake on the spot. The check digit in credit card numbers works on the same idea.

Encryption that protects the internet (RSA)

RSA, the best-known public-key encryption for sending things like credit card numbers safely, uses "the remainder of a huge power" directly in its calculations. A power mod can be computed quickly, but working backward from the result to the original number is extremely hard. This one-way property is what makes it secure.
Repeated squaring, whose steps the "Power mod" mode on this page shows, is the calculation that encryption software runs every day.

Everyday programming (even or odd, taking turns in a loop)

In programming, the % operator is used all the time: i % 2 tells even from odd, and i % n makes an order that loops around every n items (choosing the next player in a turn-based game, going back to the first slide after the last one, and so on).
When negative numbers are involved, % gives different results in different languages, so knowing "the math remainder versus % in C and Java" helps when you hunt for bugs.

Sharing equally and counting what is left (handing out, packing)

Share 63 pencils equally among 12 people, and each gets 5 with 3 left over (63 = 12 × 5 + 3). Packing stock into boxes (how many full boxes of n, and how many left over), splitting people into groups for a party: every "share equally and see what is left" situation is this calculation.
The basic division equation a = n × q + r puts all these everyday situations into one formula.

Formulas and figures

The basic division equation (what a remainder is)
Clock diagram (mod 12)
Standard notation (the usual math form)
\(a\) \(=\) \(n\) \(\times\) \(q\) \(+\) \(r\)
In words (symbols replaced with words)
④ \(a\): dividend \(=\) ① \(n\): divisor (modulus) \(\times\) ② \(q\): quotient \(+\) ③ \(r\): remainder
The formula in words
① Take the \(n\): divisor (modulus)
② multiply it by the \(q\): quotient
③ and add the \(r\): remainder (chosen so that \(0 \le r < n\))
④ and you get back the \(a\): dividend . There is exactly one way to write it in this form, and \(r\) is "the remainder of \(a\) divided by \(n\)" (\(a \bmod n\))
Quick example
Divide 38 by 12 (the same calculation that turns "hour 38" into 2 o'clock on a clock)
dividend 38 \(=\) divisor 12 \(\times\) quotient 3 \(+\) remainder 2
\(38 = 12 \times 3 + 2\)
\(38 \bmod 12 = 2\)
Key idea
In math, the remainder \(r\) is always chosen in the range \(0 \le r < n\). The same goes for negative numbers. To divide \(-7\) by \(3\), write \(-7 = 3 \times (-3) + 2\): the quotient is lowered to the smaller integer (\(-3\)) so that the remainder is \(2\) (floor division). The % operator in programming, however, works differently from language to language. In C, Java and JavaScript, -7 % 3 rounds the quotient toward 0 (to \(-2\)), so the result is \(-1\) (the remainder takes the sign of the dividend). The % operator in Python and Ruby and the MOD function in Excel give the remainder the sign of the divisor, so they return \(2\), the same as math. In programs that handle remainders of negative numbers, this difference is a common source of bugs, so be careful.
Definition of congruence (what a ≡ b (mod n) says)
Standard notation (the usual math form)
\(a - b\) \(=\) \(n\) \(\times\) \(m\)
In words (symbols replaced with words)
③ \(a - b\): difference of the two integers \(=\) ① \(n\): modulus \(\times\) ② \(m\): some integer
The formula in words
① When the \(n\): modulus
② times \(m\): some integer
③ is exactly equal to the \(a - b\): difference of the two integers (that is, when the difference is a multiple of \(n\)), you write \(a \equiv b \pmod{n}\) and say "\(a\) and \(b\) are congruent modulo \(n\)"
Quick example
38 and 14 are congruent modulo 12 (\(38 \equiv 14 \pmod{12}\))
difference (38 − 14 = 24) \(=\) modulus 12 \(\times\) integer 2
\(38 - 14 = 24 = 12 \times 2\)
\(38 \equiv 14 \pmod{12}\)
Key idea
"The difference is a multiple of \(n\)" and "the remainders when divided by \(n\) are equal" say the same thing in two ways (indeed \(38 \bmod 12 = 2\) and \(14 \bmod 12 = 2\), so the remainders match). That is why you can read a congruence as "an equation that looks only at remainders". Picture a clock: hour 38, hour 14 and hour 2 all point to the same spot on the dial. The world of mod \(n\) is a clock dial that goes around once every \(n\), and congruent numbers are numbers that land at the same spot on that dial.
Multiplication and remainders (the basis of power mod)
Standard notation (the usual math form)
\((a \times b) \bmod n\) \(=\) \(\{(a \bmod n) \times (b \bmod n)\} \bmod n\)
In words (symbols replaced with words)
② remainder of the product \(=\) ① remainder after multiplying the two remainders
The formula in words
① The remainder after multiplying the two remainders
② is the same as the remainder of the product (you may turn each number into its remainder first and then multiply)
Quick example
The remainder of 38 × 15 divided by 12 can be found from the two remainders, 2 and 3, alone
remainder of the product (38 × 15 = 570) \(=\) remainder 2 × remainder 3 = 6
\(38 \bmod 12 = 2,\quad 15 \bmod 12 = 3\)
\(2 \times 3 = 6\)
\((38 \times 15) \bmod 12 = 570 \bmod 12 = 6\)
Key idea
Thanks to this property, you never have to finish a big multiplication: you can turn the numbers into remainders first and multiply those. A power is repeated multiplication, so you can find the remainder of something like \(7^{100}\) by following only the remainders, without ever building the huge number. This is the basis of repeated squaring (square over and over, taking the remainder each time, split the exponent into a sum of powers of 2 and multiply the pieces). The "Power mod" mode of this calculator shows its steps this way. Also, a power has only \(n\) possible remainders, so it must come back to a remainder it had before and then repeat in a cycle. For example, the last digit of \(7^{k}\) (its remainder mod \(10\)) goes around 7, 9, 3, 1 in turn. Finding such a cycle is a classic technique in math contests.
Properties of congruences (adding, subtracting and multiplying both sides)
Standard notation (the usual math form)
\(a + c\) \(\equiv\) \(b + d\) \(\pmod{n}\)
\(a - c\) \(\equiv\) \(b - d\) \(\pmod{n}\)
\(a \times c\) \(\equiv\) \(b \times d\) \(\pmod{n}\)
In words (symbols replaced with words)
① \(a + c\): sum of the left sides \(\equiv\) ② \(b + d\): sum of the right sides \(\pmod{n}\)
\(a - c\): difference of the left sides \(\equiv\) \(b - d\): difference of the right sides \(\pmod{n}\)
\(a \times c\): product of the left sides \(\equiv\) \(b \times d\): product of the right sides \(\pmod{n}\)
The formula in words
① If \(a \equiv b\) and \(c \equiv d \pmod{n}\), then the sum, difference or product of the left sides
② stays congruent to the sum, difference or product of the right sides (you can add, subtract and multiply congruences just like ordinary equations)
Quick example
Using \(38 \equiv 2\) and \(15 \equiv 3 \pmod{12}\):
38 + 15 = 53 \(\equiv\) 2 + 3 = 5 \(\pmod{12}\)
\(38 + 15 = 53 \equiv 5,\quad 2 + 3 = 5 \pmod{12}\)
\(38 \times 15 = 570 \equiv 6,\quad 2 \times 3 = 6 \pmod{12}\)
Key idea
What makes this property handy is that even with big numbers, you can turn them into remainders first and then add, subtract or multiply. Division is the one thing you cannot do freely. For example, \(6 \equiv 12 \pmod{6}\) is true, but dividing both sides by 2 gives \(3 \equiv 6 \pmod{6}\), which is false (the difference 3 is not a multiple of 6). You may divide both sides only when the number you divide by and the modulus are relatively prime (their greatest common divisor is 1).
The remainder of an integer \(a\) divided by \(n\) is the \(r\) in the one and only way to write \(a = n \times q + r\) with \(0 \le r < n\). The congruence \(a \equiv b \pmod{n}\) says that the difference of \(a\) and \(b\) is a multiple of \(n\) (in other words, they have the same remainder when divided by \(n\)), and you can add, subtract and multiply congruences just like equations. Thanks to this, even the remainder of a huge power can be found quickly by repeated squaring, which follows only the remainders.

Symbols and terms

Symbols

\(\equiv\) is congruent to The symbol for congruence. It is an equals sign with three lines instead of two, and says "equal in the world of remainders", which is looser than "exactly equal".
\(\bmod\) (mod) mod Short for "modulus", from the Latin word modulus (a small measure). "\(a \bmod n\)" stands for "the remainder of \(a\) divided by \(n\)", and "\(\pmod{n}\)" written after an equation declares "we are working modulo \(n\)".
\(a,\ b\) a, b The integers whose remainders you look at. In a congruence, they are the two integers on the left and right. Letters near the start of the alphabet are traditionally used for fixed numbers.
\(n\) n The modulus (the number you divide by). The letter \(n\), from "number", is often used. On this page it is an integer of 1 or more.
\(q\) q The quotient, from the first letter of "quotient". When dividing a negative number, the quotient is rounded down to the smaller integer so that the remainder is 0 or more (floor division).
\(r\) r The remainder, from the first letter of "remainder". In math it is always chosen in the range \(0 \le r < n\).
\(m\) m The integer in the definition of congruence that tells how many times the modulus goes into the difference. It can be negative or 0.
\(a^{k}\) a to the k \(a\) multiplied by itself \(k\) times (a power). The small raised number \(k\) is the exponent, which tells how many times to multiply.
% percent (as an operator, mod) The modulo operator that finds a remainder in many programming languages. It is the same sign as the percent sign but has a different job. In C, Java and JavaScript, its result for negative numbers can differ from the math remainder (see the key idea of formula card 1).

Terms

remainder (residue) What is left over when a division does not come out even. "Residue" is a more formal word for the same thing. In math it is always at least \(0\) and less than the divisor.
quotient The integer that tells how many times the divisor can be taken away. It is the \(q\) in the basic division equation \(a = n \times q + r\).
modulus The number \(n\) you divide by to get the remainders you work with. On a clock dial, it is the number of marks in one full turn. "Modulo 12" is short for "looking at remainders when divided by 12".
congruent Two integers are congruent modulo \(n\) when they have the same remainder when divided by \(n\). This is a term about integers, different from congruent shapes in geometry (same shape and size).
congruence A statement of the form \(a \equiv b \pmod{n}\). You can add, subtract and multiply congruences just like equations, so remainder problems can be worked out by rewriting. It is a basic tool of number theory, used in math contests and computer science.
multiple A number you get by multiplying an integer by another integer. "The difference is a multiple of the modulus" is the definition of congruence.
floor division A way of dividing that rounds the quotient down to the smaller integer. When the divisor is positive, the remainder is 0 or more even for a negative dividend. The // operator in Python and the INT function in Excel work this way.
modulo operator The % operator that finds a remainder in programming. C, Java and JavaScript round the quotient toward 0 (the remainder takes the sign of the dividend). Python and Ruby use floor division (the remainder takes the sign of the divisor, so it is 0 or more when the modulus is positive).
repeated squaring A way to find the remainder of a huge power with few multiplications: square over and over while taking the remainder, split the exponent into a sum of powers of 2 and multiply the pieces. It is also called exponentiation by squaring or square-and-multiply, and is used in implementations of RSA encryption and more.
residue class The idea of grouping integers by their remainder when divided by \(n\). In the world of mod \(n\), every integer falls into one of \(n\) groups, remainders \(0\) to \(n-1\). Even and odd numbers are the grouping by remainder when divided by 2.
periodicity The way the remainders of powers repeat the same pattern. There are only \(n\) possible remainders, so they must come back to one they had before. Finding the cycle in last-digit problems (mod 10) is a classic in math contests.
relatively prime Two integers are relatively prime (or coprime) when their greatest common divisor is 1. It appears in the condition for dividing both sides of a congruence by the same number.

Good to know before you start

Here is what helps you use the calculation on this page with real understanding, not just by pressing the button.
If you get stuck, going back to these topics is the quickest way forward.

Division with remainders (Grades 3–4)
  • Being able to calculate \(17 \div 5 = 3\) remainder \(2\)
  • Being able to check it with "divisor × quotient + remainder = dividend"
Multiples and factors (Grades 4–6)
  • Knowing that \(24\) is a multiple of \(12\)
  • Knowing what the greatest common factor is (it is used in the condition "relatively prime" for dividing a congruence)
Negative numbers (Grades 6–7)
  • Being able to add, subtract and multiply with negative numbers (for example, \(3 \times (-3) = -9\))
  • Knowing that \(-3\) is less than \(-2\) (to its left) on the number line
Exponents (Grades 6–8)
  • Knowing that the raised exponent tells how many times to multiply, as in \(3^{4} = 3 \times 3 \times 3 \times 3 = 81\)
  • Being able to use the laws of exponents \(a^{m} \times a^{n} = a^{m+n}\) and \((a^{m})^{n} = a^{mn}\) (they are why repeated squaring works)
The division algorithm for integers (high school)
  • Knowing that dividing an integer \(a\) by a positive integer \(n\) can be written as \(a = nq + r\) (with \(0 \le r < n\)) in exactly one way
  • Having met the idea of grouping integers by their remainders (even and odd numbers are the grouping by remainder when divided by 2)

How to calculate it in Excel

Copy the whole table below and paste it into cell A1 in Excel. It works as is.
Table to find a mod n (the remainder)
Dividend a -7
Modulus (divisor) n 3
Math remainder (0 or more) =MOD(B1,B2)
Quotient (floor division) =INT(B1/B2)
Check n × quotient + remainder =B2*B4+B3
C/Java-style remainder (rounded toward 0) =B1-B2*TRUNC(B1/B2)
Table to check a ≡ b (mod n)
Integer a 38
Integer b 14
Modulus n 12
Difference a − b =B1-B2
Remainder of the difference ÷ n =MOD(B4,B3)
Result (TRUE = congruent) =MOD(B4,B3)=0
Table to find a power mod n (repeated squaring)
Base a 7
Exponent k 100
Modulus n 13
Remainder of a^1 =MOD(B1,B3)
Remainder of a^2 (square the row above, take the remainder) =MOD(B4^2,$B$3)
Remainder of a^4 =MOD(B5^2,$B$3)
Remainder of a^8 =MOD(B6^2,$B$3)
Remainder of a^16 =MOD(B7^2,$B$3)
Remainder of a^32 =MOD(B8^2,$B$3)
Remainder of a^64 =MOD(B9^2,$B$3)
Remainder combined for 100 = 64 + 32 + 4 =MOD(MOD(B10*B9,$B$3)*B6,$B$3)
After pasting, just change the upper rows (the inputs), and the lower rows are calculated automatically.
Excel's MOD function returns the same "math remainder" (0 or more) as this calculator. Even for negative numbers, =MOD(-7,3) is 2. If you need the C/Java-style remainder, use the last row of the first table, which uses TRUNC to round the quotient toward 0.
The first table divides −7 by 3: the remainder is 2 and the quotient is −3.
The second table checks 38 ≡ 14 (mod 12). The remainder of the difference 24 is 0, so it shows TRUE (congruent).
The third table finds the remainder of 7 to the 100th power divided by 13 by repeated squaring. The answer is 9. "^" is the power sign. Excel handles only about 15 digits exactly, so when the modulus n has more than 7 digits, the squared values lose precision. In that case, use the calculator on this page or Python.

How to calculate it in Google Sheets

Copy the whole table below and paste it into cell A1 in Google Sheets. It works as is.
Table to find a mod n (the remainder)
Dividend a -7
Modulus (divisor) n 3
Math remainder (0 or more) =MOD(B1,B2)
Quotient (floor division) =INT(B1/B2)
Check n × quotient + remainder =B2*B4+B3
C/Java-style remainder (rounded toward 0) =B1-B2*TRUNC(B1/B2)
Table to check a ≡ b (mod n)
Integer a 38
Integer b 14
Modulus n 12
Difference a − b =B1-B2
Remainder of the difference ÷ n =MOD(B4,B3)
Result (TRUE = congruent) =MOD(B4,B3)=0
Table to find a power mod n (repeated squaring)
Base a 7
Exponent k 100
Modulus n 13
Remainder of a^1 =MOD(B1,B3)
Remainder of a^2 (square the row above, take the remainder) =MOD(B4^2,$B$3)
Remainder of a^4 =MOD(B5^2,$B$3)
Remainder of a^8 =MOD(B6^2,$B$3)
Remainder of a^16 =MOD(B7^2,$B$3)
Remainder of a^32 =MOD(B8^2,$B$3)
Remainder of a^64 =MOD(B9^2,$B$3)
Remainder combined for 100 = 64 + 32 + 4 =MOD(MOD(B10*B9,$B$3)*B6,$B$3)
The same formulas as in Excel (MOD, INT, TRUNC) work as is. Copy the whole table, paste it into cell A1, and replace the inputs with your own numbers.

How to calculate it in Python

a = -7
n = 3

# Python's % returns the same "math remainder" as this calculator (0 or more when the modulus is positive)
print(a % n)                 # 2

# divmod returns the floor-division quotient and the remainder together (a = n × quotient + remainder)
quotient, remainder = divmod(a, n)
print(quotient, remainder)   # -3 2

# congruence check: is 38 ≡ 14 (mod 12)? (check whether the difference is a multiple of 12)
print((38 - 14) % 12 == 0)   # True

# power mod: remainder of 7 to the 100th power divided by 13
# the 3-argument pow uses repeated squaring, so it finishes instantly even for huge exponents
print(pow(7, 100, 13))       # 9

def c_style_mod(x, m):
    # same result as % in C, Java and JavaScript (quotient rounded toward 0)
    r = x % m
    if r != 0 and x < 0:
        r -= m
    return r

print(c_style_mod(-7, 3))    # -1
Python's % operator matches the math remainder. When the divisor is positive, it returns a value of 0 or more even for negative numbers (-7 % 3 is 2). For power mod, the 3-argument form pow(base, exponent, modulus) runs repeated squaring inside, so it finds just the remainder quickly even for powers with tens of thousands of digits. When you need the same result as % in C, Java and JavaScript, add a correction that rounds the quotient toward 0, as in the last function.

How to write it in LaTeX and other math languages (copy and paste)

The basic division equation (what a remainder is)
a = n × q + r (0 ≤ r < n)
a = nq + r \quad (0 \le r < n)
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <mi>a</mi><mo>=</mo><mi>n</mi><mi>q</mi><mo>+</mo><mi>r</mi>
    <mo>,</mo>
    <mn>0</mn><mo>&#x2264;</mo><mi>r</mi><mo>&lt;</mo><mi>n</mi>
  </mrow>
</math>
a = n q + r, \ 0 <= r < n
{Quotient[a, n], Mod[a, n]}
q := floor(a/n); r := a mod n;
q = floor(a/n); r = mod(a, n);
a = nq + r (0 ≤ r < n)
Definition of congruence (what a ≡ b (mod n) says)
a ≡ b (mod n)  ⇔  a − b = n × m
a \equiv b \pmod{n} \iff a - b = nm
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <mi>a</mi><mo>&#x2261;</mo><mi>b</mi>
    <mspace width="0.3em"/>
    <mo>(</mo><mi>mod</mi><mspace width="0.3em"/><mi>n</mi><mo>)</mo>
    <mo>&#x21D4;</mo>
    <mi>a</mi><mo>&#x2212;</mo><mi>b</mi><mo>=</mo><mi>n</mi><mi>m</mi>
  </mrow>
</math>
a -= b (mod n) iff a - b = n m
Mod[a - b, n] == 0
(a - b) mod n = 0;
mod(a - b, n) == 0
a ≡ b (mod n)
Multiplication and remainders (the basis of power mod)
(a × b) mod n = {(a mod n) × (b mod n)} mod n
(a \times b) \bmod n = \{(a \bmod n)(b \bmod n)\} \bmod n
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <mo>(</mo><mi>a</mi><mo>&#xD7;</mo><mi>b</mi><mo>)</mo>
    <mspace width="0.3em"/><mi>mod</mi><mspace width="0.3em"/><mi>n</mi>
    <mo>=</mo>
    <mo>{</mo>
    <mo>(</mo><mi>a</mi><mspace width="0.3em"/><mi>mod</mi><mspace width="0.3em"/><mi>n</mi><mo>)</mo>
    <mo>&#xD7;</mo>
    <mo>(</mo><mi>b</mi><mspace width="0.3em"/><mi>mod</mi><mspace width="0.3em"/><mi>n</mi><mo>)</mo>
    <mo>}</mo>
    <mspace width="0.3em"/><mi>mod</mi><mspace width="0.3em"/><mi>n</mi>
  </mrow>
</math>
(a * b) mod n = ((a mod n) * (b mod n)) mod n
Mod[a b, n] == Mod[Mod[a, n] Mod[b, n], n]
(a * b) mod n = ((a mod n) * (b mod n)) mod n;
mod(a*b, n) == mod(mod(a, n)*mod(b, n), n)
(a×b) mod n = ((a mod n)×(b mod n)) mod n
Properties of congruences (adding, subtracting and multiplying both sides)
a ≡ b, c ≡ d (mod n) ⇒ a+c ≡ b+d, a−c ≡ b−d, a×c ≡ b×d (mod n)
a \equiv b,\ c \equiv d \pmod{n} \Rightarrow a + c \equiv b + d,\ a - c \equiv b - d,\ ac \equiv bd \pmod{n}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <mi>a</mi><mo>+</mo><mi>c</mi><mo>&#x2261;</mo><mi>b</mi><mo>+</mo><mi>d</mi>
    <mo>,</mo>
    <mi>a</mi><mo>&#x2212;</mo><mi>c</mi><mo>&#x2261;</mo><mi>b</mi><mo>&#x2212;</mo><mi>d</mi>
    <mo>,</mo>
    <mi>a</mi><mi>c</mi><mo>&#x2261;</mo><mi>b</mi><mi>d</mi>
    <mspace width="0.3em"/>
    <mo>(</mo><mi>mod</mi><mspace width="0.3em"/><mi>n</mi><mo>)</mo>
  </mrow>
</math>
a + c -= b + d, \ a - c -= b - d, \ a c -= b d (mod n)
Mod[a + c, n] == Mod[b + d, n] && Mod[a - c, n] == Mod[b - d, n] && Mod[a c, n] == Mod[b d, n]
(a + c) mod n = (b + d) mod n;
mod(a + c, n) == mod(b + d, n)
a + c ≡ b + d (mod n)

How to have ChatGPT  do the calculation

You are a math calculation assistant for number theory (properties of integers). Do the following calculation by actually running Python code, and base your answer only on the numbers from the execution result (do not answer by mental math or guessing).

Calculate the following 3 problems.
1. The math remainder of −7 divided by 3 (chosen to be 0 or more), and the quotient
2. Whether 38 ≡ 14 (mod 12) holds (also show whether the difference is a multiple of 12)
3. The remainder of 7 to the 100th power divided by 13 (use pow(7, 100, 13))

Use Python's %, divmod and pow(base, exponent, modulus), and show the formulas you used and the numbers from the execution result.

How to Use
  1. 1
    Enter your numbers
    Type the numbers you want to calculate with into the input fields
  2. 2
    Calculate
    Press the "Calculate" button
  3. 3
    Check the result
    The result appears on the spot. The same page also explains the idea behind the calculation and the formula
  DataChef Features
Easy and Free
Unlimited conversions for free.
No technical knowledge required.
Intuitive and user-friendly operation.
No Registration Required
Available immediately after access.
Can be used without registering personal information.
Safe and Secure
Fully SSL encrypted communication.
Automatic file deletion by clicking "download".
Fast
High-speed site access
and rapid file conversion.
No Watermark
No watermark.
No attribution required.
Commercial Use Available
Free for commercial use.
No need to contact us for commercial use permission.