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 week ago - In mathematics, the result of the modulo operation is an equivalence class, and any member of the class may be chosen as representative; however, the usual representative is the least positive residue, the smallest non-negative integer that belongs to that class (i.e., the remainder of the ...
🌐
CalculatorSoup
calculatorsoup.com › calculators › math › modulo-calculator.php
Modulo Calculator
Modulo calculator finds a mod b, the remainder when a is divided by b. The modulo operation returns the remainder in division of 2 positive or negative numbers or decimals.
Discussions

Can someone explain the modulo operation to me like I'm five? (Credit.c)
It's the remainder you get from division. Let's say you were dividing 6 by 3. 3 goes two times in 6 and leaves no remainder. So 6 % 3 is 0. Now, if you were dividing 5 by 3, 3 goes once in 5 and that leaves 2. So 5 % 3 is 2. Let's do some more digits. Let's say we have a number like 824. If we divide this by 10 we get 82 with a remainder of 4. Now if divide 591 by 10, that leaves us with a remainder of 1. Divide 600 by 10, and you get a remainder of zero. 600 % 10 is zero. So we can always get the last digit in a number by using % 10. If you take an integer in C and divide by 10, that's the same as chopping off the rightmost digit, since integer division always rounds down. So if you want to go through a number, digit by digit, you loop through it by first doing % 10 to get the last digit, and doing /= 10 to get to the next digit. I hope that helped. More on reddit.com
🌐 r/cs50
7
31
April 24, 2020
Struggling to understand the modulus operator when the number being divided BY is smaller than the number dividing.
Here's the ELI5 version (which may sound kind of condescending, for which I apologize but then again, you are 5 years old): a / b asks the question: given a objects and b people, how many objects can each person get? a % b asks the question: after giving each person that many objects, how many objects remain? Therefore, 10 / 6 yields 1, because if you have 10 donuts and 6 people, each person can get one donut. 10 % 6 yields 4, because once you've given every person a donut, there are 4 donuts remaining. 6 / 10 yields 0, because if you have 6 donuts and 10 people, nobody can get a donut. 6 % 10 yields 6, because once you've given zero donuts to everyone, there remains 6 donuts. More on reddit.com
🌐 r/learnprogramming
26
1
October 6, 2014
Modulo operator
A modulo is a mathematical operator used in modular arithmetic You can think about modular arithmetic like how time on an analog clock works. In a 12 hr clock, if it’s currently 10, in 3 hours it will be 1, not 13. This is expressed as 10 + 3 mod 12. The modulo operator returns that result. num = (10 + 3) % 12 print(num) Would output 1. People like thinking about this as the remainder, but that’s not really accurate. For example: -1 % 4 would actually equal 3. If you think about a 4-hr clock and go back 1 hour, you end up at 3. More on reddit.com
🌐 r/learnpython
48
24
November 22, 2023
What the HELL is a modulo?
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 More on reddit.com
🌐 r/learnjava
31
0
July 13, 2016
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.

🌐
Josh W. Comeau
joshwcomeau.com › javascript › modulo-operator
Understanding the JavaScript Modulo Operator • Josh W. Comeau
One of the most commonly-misunderstood operators is Modulo (%). In this tutorial, we'll unpack exactly what this little bugger does, and learn how it can help us solve practical problems.
🌐
Reddit
reddit.com › r/cs50 › can someone explain the modulo operation to me like i'm five? (credit.c)
r/cs50 on Reddit: Can someone explain the modulo operation to me like I'm five? (Credit.c)
April 24, 2020 -

So I'm really struggling with the credit problem in pset1. I'm completely new to coding and computer science and everything but I really want to try doing all of the problems in this class. I had to look up mario and cash to gain some insight into what I've been doing wrong when I approach a problem. With each completed problem the pieces come together in my head a little more than they were before.

Credit has me totally through a loop. It seems like for all of the problems I understand what to use in C as far as loops and what have you but I really struggle with figuring out what like operations I'm supposed to use to tell the program exactly what to do. With the whole modulo operation thing I don't really understand what it's doing and what I have to do to get it to give me the numbers I need. Something tells me I need to use different powers of ten to somehow separate the full credit card number into individual digits but because I don't understand what % 10 is actually doing I can't fully figure out what I need to do.

I'm struggling with trying to decide if I should just skip this problem and try again another time or if I should contemplate it more. With each problem it seems like I struggle with like some kind of mathematical aspect, I feel like there's something that I'm missing but I can't tell if I just how to make myself think about things differently. I feel like I'm making myself crazy about this lol

🌐
Math is Fun
mathsisfun.com › numbers › › modulo.html
Modulo Operation
The modulo (or "modulus" or "mod") is the remainder after dividing one number by another.
Find elsewhere
🌐
Processing
processing.org › reference › modulo.html
% (modulo) / Reference / Processing.org
That is, a number cannot be divided by any number larger than itself. For example, when 9 is divided by 10, the result is zero with a remainder of 9. Thus, 9 % 10 produces 9. Modulo is extremely useful for ensuring values stay within a boundary, such as when keeping a shape on the screen.
🌐
Runestone Academy
runestone.academy › ns › books › published › thinkcpp › Chapter4 › TheModulusOperator.html
4.1. The Modulus Operator — How to Think Like a Computer Scientist - C++
The modulus operator works on integers (and integer expressions) and yields the remainder when the first operand is divided by the second.
🌐
GeeksforGeeks
geeksforgeeks.org › computer science fundamentals › modulus-operator-in-programming
Modulus Operator in Programming - GeeksforGeeks
March 26, 2024 - The modulus operator, often represented by the symbol '%', is a fundamental arithmetic operator used in programming languages to find the remainder of a division operation between two numbers.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › modulo-operator-in-c-cpp-with-examples
Modulo Operator (%) in C/C++ with Examples - GeeksforGeeks
July 12, 2025 - In C or C++, the modulo operator (also known as the modulus operator), denoted by %, is an arithmetic operator.
🌐
The Data School
thedataschool.co.uk › a › henry-mak › modulo-operator-intro
A short introduction to the Modulo Operator - The Data School
For example 1, 10 divided by 10 is 1 remainder 0. For example 2, 10 divided by 2 is 5 remainder 0. For example 3, 10 divided by 3 is 3 remainder 1. For example 4, 100 divided by 13 is 7 remainder 9. If it's not clear enough already, it's the remainder of the division which is the answer of the modulo operation.
🌐
Reddit
reddit.com › r/learnprogramming › struggling to understand the modulus operator when the number being divided by is smaller than the number dividing.
r/learnprogramming on Reddit: Struggling to understand the modulus operator when the number being divided BY is smaller than the number dividing.
October 6, 2014 -

To preface this, I have been exposed to this concept numerous times, asked teachers/TA's, and even Googled and read answers, frankly I am still lost.

What I know is that the % "modulus" operator performs remainder division on two integers.

I understand that 10 % 6 would be four, but do not understand how to calculate 6 % 10.

I REALLY want to understand, specifically because it is necessary for wrapping around collections/various things.

If someone can dumb it down HARD for me, that is what I need.

I am trying to relate it to something like a = b * q + r because my understanding is that is how it "literally" works.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Remainder
Remainder (%) - JavaScript | MDN
To obtain a modulo in JavaScript, in place of n % d, use ((n % d) + d) % d. In JavaScript, the modulo operation (which doesn't have a dedicated operator) is used to normalize the second operand of bitwise shift operators (<<, >>, etc.), making the offset always a positive value.
🌐
UCI Music
music.arts.uci.edu › dobrian › maxcookbook › modulo-operator
Modulo operator: % | Max Cookbook
The % object is the arithmetic operator “modulo” (a.k.a. “mod”), used in modular arithmetic. Whereas the / object (“divided by”) divides the left input by the right input and outputs the quotient, the % object divides the left input by the right output and outputs the remainder.
🌐
Real Python
realpython.com › python-modulo-operator
Python Modulo Operator (%): How to Use Mod in Python – Real Python
April 1, 2023 - Python supports a wide range of arithmetic operators that you can use when working with numbers in your code. One of these operators is the modulo operator (%), which returns the remainder of dividing two numbers.
🌐
Perl.com
perl.com › article › 46 › 2013 › 11 › 4 › Understanding-the-modulo-operator
Understanding the modulo operator
November 4, 2013 - Mathematically this is expected, however that is why the characterization of modulo as returning the “remainder of a division operation” can catch programmers by surprise - it does not return a fractional decimal.
🌐
Reddit
reddit.com › r/learnjava › what the hell is a modulo?
r/learnjava on Reddit: What the HELL is a modulo?
July 13, 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