computational operation
In computing and mathematics, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another, the latter being called the modulus of the operation. … Wikipedia
🌐
Wikipedia
en.wikipedia.org β€Ί wiki β€Ί Modulo
Modulo - Wikipedia
1 day ago - Given two positive numbers a and ... the expression "5 mod 2" evaluates to 1, because 5 divided by 2 has a quotient of 2 and a remainder of 1, while "9 mod 3" would evaluate to 0, because 9 divided by 3 has a quotient of 3 and a remainder of 0....
🌐
BetterExplained
betterexplained.com β€Ί articles β€Ί fun-with-modular-arithmetic
Fun With Modular Arithmetic – BetterExplained
Give people numbers 0, 1, 2, and ... by 4 β€” whoever gets the remainder exactly goes first. (For example: if the sum of fingers is 11, whoever had β€œ3” gets to go first, since 11 mod 4 = 3)....
🌐
Calcworkshop
calcworkshop.com β€Ί home β€Ί number theory β€Ί modular arithmetic
Modular Arithmetic (w/ 17 Step-by-Step Examples!)
February 1, 2021 - If n is a positive integer then ... and b congruent modulo n if their difference is a multiple of n. For example, 7 and 4 are congruent modulo 3 because not only are they in the same equivalence class, but their difference 7-4 ...
🌐
Wikipedia
en.wikipedia.org β€Ί wiki β€Ί Modular_arithmetic
Modular arithmetic - Wikipedia
1 week ago - For example, International Standard Book Number (ISBN) uses modulo 11 (for 10-digit ISBN) or modulo 10 (for 13-digit ISBN) arithmetic for error detection. Likewise, International Bank Account Numbers (IBANs) use modulo 97 arithmetic to spot ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί c++ β€Ί modulo-operator-in-c-cpp-with-examples
Modulo Operator (%) in C/C++ with Examples - GeeksforGeeks
July 12, 2025 - The modulo operator has few restrictions or limitations on it. The % modulus operator cannot be applied to floating-point numbers i.e. float or double.
🌐
Math is Fun
mathsisfun.com β€Ί numbers β€Ί modulo.html
Modulo Operation
You can also play with adding numbers using different modulo values here:
🌐
Reddit
reddit.com β€Ί r/learnjava β€Ί what the hell is a modulo?
r/learnjava on Reddit: What the HELL is a modulo?
July 18, 2016 -

I have a test tomorrow, in the test one of the questions will be to seperate a number from a 3 digit number, say I have 641, I need to know how to print out 6,4 and 1 seperately.

What the hell do I do ? The teacher is so bad I couldn't understand a word she said and neither did my class, we already complained about her but this isn't the issue, the issue is that I have no easy answers on the internet for what the modulo is.

Why does doing (n/100)%10; print out the hundred digit ? I have no idea how this works, please go easy on me.

Top answer
1 of 5
3
The modulo operator returns the "remainder" of a division. If you think back to your early days at school, when you first learned dividing using long divisions , you learned that for 14/4 the result is 3 and the remainder is 2. Because "4" fits "3" times in '14", but then you still have a remainder of "2" so that: 14 = 4 x 3 + 2 Now, why do they suggest using the modulo operator to get the different numbers (6, 4, 1). Well, let's start from the right. If we divide 641/10, we know that it fits 64 times inside 641 and the remainder is 1. In java terms this is: int lastDigit = 641 % 10; // 1 Now, you can repeat the same process over and over again, however, we need to "shift" the number a bit. For example, if we want to know the second digit, we first divide 641 by 10, so that we only have 64. Now we can just retrieve the last digit again by using the modulo operator: int secondDigit = 641 / 10 % 10; // = 64 % 10 = 4 Now, you should start to see a system here. You can keep doing this trick over and over again, but in stead of dividing by 10, you divide by 100, 1000, 10000, 100000, ... and you get the next digit every time. In your case, the left digit can be retrieved by using: int firstDigit = 641 / 100 % 10; // = 6 % 10 = 6 In this case, it's pretty "useless" to use the modulo operator, because if you have a number with only 3 digits, dividing by 100 will already yield the left most digit. However, let's say that our number was 1234, then we would get: int digit = 1234 / 100 % 10; // = 12 % 10 = 2
2 of 5
1
Modulo is the remainder from integer division. 4 / 3 = 1 r 1 4 % 3 = 1
Find elsewhere
Top answer
1 of 9
226

(This explanation is only for positive numbers since it depends on the language otherwise)

Definition

The modulo operation returns the remainder or signed remainder of a division, after one number is divided by another, the latter being called the modulus of the operation. (source: wikipedia)

For instance, 9 divided by 4 equals 2 but it remains 1. Here, 9 / 4 = 2 and 9 % 4 = 1.

Image source: Wikimedia

In your example: 5 divided by 7 gives 0 but it remains 5 (5 % 7 == 5).

Calculation

The modulo operation can be calculated using this equation:

a % b = a - floor(a / b) * b
  • floor(a / b) represents the number of times you can divide a by b
  • floor(a / b) * b is the amount that was successfully shared entirely
  • The total (a) minus what was shared equals the remainder of the division

Applied to the last example, this gives:

5 % 7 = 5 - floor(5 / 7) * 7 = 5

Modular Arithmetic

That said, your intuition was that it could be -2 and not 5. Actually, in modular arithmetic, -2 = 5 (mod 7) because it exists k in Z such that 7k - 2 = 5.

You may not have learned modular arithmetic, but you have probably used angles and know that -90Β° is the same as 270Β° because it is modulo 360. It's similar, it wraps! So take a circle, and say that its perimeter is 7. Then you read where is 5. And if you try with 10, it should be at 3 because 10 % 7 is 3.

2 of 9
37

Two Steps Solution.

Some of the answers here are complicated for me to understand. I will try to add one more answer in an attempt to simplify the way how to look at this.


Short Answer:

Example 1:

7 % 5 = 2

Each person should get one pizza slice.

Divide 7 slices on 5 people and every one of the 5 people will get one pizza slice and we will end up with 2 slices (remaining). 7 % 5 equals 2 is because 7 is larger than 5.


Example 2:

5 % 7 = 5

Each person should get one pizza slice

It gives 5 because 5 is less than 7. So by definition, you cannot divide whole 5items on 7 people. So the division doesn't take place at all and you end up with the same amount you started with which is 5.


Programmatic Answer:

The process is basically to ask two questions:

Example A: (7 % 5)

(Q.1) What number to multiply 5 in order to get 7?

Two Conditions: Multiplier starts from `0`. Output result should not exceed `7`. 

Let's try:

Multiplier is zero 0 so, 0 x 5 = 0

Still, we are short so we add one (+1) to multiplier.

1 so, 1 x 5 = 5

We did not get 7 yet, so we add one (+1).

2 so, 2 x 5 = 10

Now we exceeded 7. So 2 is not the correct multiplier. Let's go back one step (where we used 1) and hold in mind the result which is5. Number 5 is the key here.

(Q.2) How much do we need to add to the 5 (the number we just got from step 1) to get 7?

We deduct the two numbers: 7-5 = 2.

So the answer for: 7 % 5 is 2;


Example B: (5 % 7)

1- What number we use to multiply 7 in order to get 5?

Two Conditions: Multiplier starts from `0`. Output result and should not exceed `5`. 

Let's try:

0 so, 0 x 7 = 0

We did not get 5 yet, let's try a higher number.

1 so, 1 x 7 = 7

Oh no, we exceeded 5, let's get back to the previous step where we used 0 and got the result 0.

2- How much we need to add to 0 (the number we just got from step 1) in order to reach the value of the number on the left 5?

It's clear that the number is 5. 5-0 = 5

   5 % 7 = 5

Hope that helps.

🌐
Real Python
realpython.com β€Ί python-modulo-operator
Python Modulo in Practice: How to Use the % Operator – Real Python
April 1, 2023 - The modulo operator is used when you want to compare a number with the modulus and get the equivalent number constrained to the range of the modulus. For example, say you want to determine what time it would be nine hours after 8:00 a.m. On a ...
🌐
Matthew J. Clemente
blog.mattclemente.com β€Ί 2019 β€Ί 07 β€Ί 12 β€Ί modulus-operator-modulo-operation
What is the Modulus Operator? A Short Guide with Practical Use Cases | Matthew J. Clemente
July 12, 2019 - Here's an example of incrementing numbers with a modulus of 3: 0 % 3 = 0 1 % 3 = 1 2 % 3 = 2 3 % 3 = 0 // cycle back to 0 4 % 3 = 1 5 % 3 = 2 6 % 3 = 0 // cycle back to 0 Β· Notice how the result of the modulo operation keeps repeating 0-1-2; the values wrap around.
🌐
American Institute of Mathematics
aimath.org β€Ί news β€Ί congruentnumbers β€Ί modulo.html
Basics about congruences and "modulo"
We say integers a and b are "congruent modulo n" if their difference is a multiple of n. For example, 17 and 5 are congruent modulo 3 because 17 - 5 = 12 = 4β‹…3, and 184 and 51 are congruent modulo 19 since 184 - 51 = 133 = 7β‹…19. We often write this as 17 ≑ 5 mod 3 or 184 ≑ 51 mod 19.
🌐
Federico Hatoum
hatoum.com β€Ί blog β€Ί 2012 β€Ί 12 β€Ί practical-uses-for-modulo-operator.html
Practical uses for the modulo operator β€” Federico Hatoum
August 28, 2013 - If you need to turn an elapsed number of seconds into Hours, Minutes and Seconds, modulo comes in handy. hours:int = seconds / 3600; minutes:int = (seconds / 60) % 60; seconds:int = seconds % 60; starting with 582 seconds: hours = 582 / 3600 = 0 // integer would round this to 0 minutes = (582 ...
🌐
Mathematics LibreTexts
math.libretexts.org β€Ί bookshelves β€Ί combinatorics and discrete mathematics β€Ί a spiral workbook for discrete mathematics (kwong) β€Ί 5: basic number theory
5.7: Modular Arithmetic - Mathematics LibreTexts
July 7, 2021 - In the clock example, we essentially regard 27 o’clock the same as 3 o’clock. They key is, we are only interested in the remainder when a value is divided by 12. ... Let \(n\geq2\) be a fixed integer. We say the two integers \(m_1\) and \(m_2\) are congruent modulo, denoted \[m_1 \equiv m_2 \pmod{n} \nonumber\] if and only if \(n\mid (m_1-m_2)\).
🌐
Random Tech Thoughts
randomtechthoughts.blog β€Ί 2023 β€Ί 09 β€Ί 17 β€Ί modulo-arithmetic-in-everyday-life-and-code
Modulo arithmetic in everyday life and code – Random Tech Thoughts
September 18, 2023 - Another example of modulo arithmetic is music. Music pitches are represented by the letters A-G (with occasional sharp or flat signs).
Top answer
1 of 8
13

What about using it to calculate the day of the week for some future date? I'm just spitballing here but something like...

"Today is Tuesday. Jacob knows that his math test is going to be in 17 days. What day of the week will his math test be on?"

This type of problem is very accessible and can be solved without explicitly using modular arithmetic. I would imagine this to be a good warm up problem just to get students thinking about "wrapping around" and similar concepts. After discussing, you could then ask

"Today is a Friday. Janet knows that her mother's birthday is in 241 days. What day of the week will her mother's birthday fall on?"

which is easy with modular arithmetic, but would be tedious to do week by week. I feel like these are good, contextual examples that might actually be useful for students every once in awhile. Also, the intuitive way of solving these problems, where you would divide by 7, find the remainder, and add that to the current day, is modular arithmetic, which may make it stick more readily. Also, the modular base is a small number, 7, which I have found helps students to understand mod operations easier.

2 of 8
11

I've always preferred the module 60 argument in seconds per minute. This is closer to the actual modulo arithmetic than the 12 or 24 hour clock. We might say things like:

30 minutes and 14 seconds

but would never say

30 minutes and 60 seconds

we would say

31 minutes (and 0 seconds)

This same idea also works with minutes per hour.

🌐
Computer Hope
computerhope.com β€Ί jargon β€Ί m β€Ί modulo.htm
What Is Modulo?
Modular arithmetic is the field of mathematics which concerns these types of operations, where values "wrap around" (reset to zero) when they reach a modulus value. Modular arithmetic is extremely important in the field of cryptography, which encodes information using modulo operations with large modulus.
🌐
Omni Calculator
omnicalculator.com β€Ί math β€Ί modulo
Modulo Calculator
May 8, 2025 - Two numbers, a and b, are said to be congruent modulo n if their difference a - b is divisible by n, i.e., a - b is a multiple of n. For example, 24 and 34 are congruent modulo 10 because their difference 24 - 34 = -10 is a multiple of 10.
🌐
Art of Problem Solving
artofproblemsolving.com β€Ί wiki β€Ί index.php β€Ί Modular_arithmetic β€Ί Introduction
Modular arithmetic/Introduction - AoPS Wiki
Let's use a clock as an example, except let's replace the at the top of the clock with a . This is the way in which we count in modulo 12. When we add to , we arrive back at . The same is true in any other modulus (modular arithmetic system).