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
2 weeks ago - 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. Given two positive numbers a and n, a modulo n (often abbreviated as a mod n) is the remainder ...
🌐
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 - I was not taught %, the modulus operator, which I recently discovered can be quite useful and interesting in its own right. The modulus operator, written in most programming languages as % or mod, performs what is known as the modulo operation.
🌐
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.
🌐
Wikipedia
en.wikipedia.org › wiki › Modular_arithmetic
Modular arithmetic - Wikipedia
5 days ago - This notation is not to be confused with the notation b mod m (without parentheses), which refers to the remainder of b when divided by m, known as the modulo operation: that is, b mod m denotes the unique integer r such that 0 ≤ r < m and r ≡ b (mod m).
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.

🌐
Mathematics LibreTexts
math.libretexts.org › campus bookshelves › mount royal university › higher arithmetic › 3: modular arithmetic
3.1: Modulo Operation - Mathematics LibreTexts
November 22, 2024 - Let \(m\) \(\in\) \(\mathbb{Z_+}\). \(a\) is congruent to \(b\) modulo \(m\) denoted as \( a \equiv b (mod \, n) \), if \(a\) and \(b\) have the remainder when they are divided by \(n\), for \(a, b \in \mathbb{Z}\).
🌐
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.
Find elsewhere
🌐
BetterExplained
betterexplained.com › articles › fun-with-modular-arithmetic
Fun With Modular Arithmetic – BetterExplained
The modulo operation (abbreviated “mod”, or “%” in many programming languages) is the remainder when dividing. For example, “5 mod 3 = 2” which means 2 is the remainder when you divide 5 by 3. Converting everyday terms to math, an “even number” is one where it’s “0 mod 2” ...
🌐
MathWorks
mathworks.com › matlab › mathematics › elementary math › arithmetic operations
mod - Remainder after division (modulo operation) - MATLAB
b = mod(a,m) returns the remainder after division of a by m, where a is the dividend and m is the divisor. This function is often called the modulo operation, which can be expressed as b = a - m.*floor(a./m).
🌐
Omni Calculator
omnicalculator.com › math › uses-of-modulo
Modulo Operator: Practical Uses in Arithmetics
June 5, 2023 - Modulo is a mathematical operation that means computing the remainder of a division of one integer by some other integer (integers are whole numbers).
🌐
My Blog
quickmentalmaths.com › modulus-operator
What is Modulus Operator in Mathematics? [Practical Examples]
April 27, 2025 - If a number is not perfectly divided by another number, the leftover is the modulus. ... “The modulus operator is a mathematical function; it returns the remainder when one number is not perfectly divided by another.”
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Remainder
Remainder (%) - JavaScript | MDN
Note that while in most languages, '%' is a remainder operator, in some (e.g., Python, Perl) it is a modulo operator. Modulo is defined as k := n - d * q where q is the integer such that k has the same sign as the divisor d while being as close to 0 as possible.
🌐
Khan Academy
khanacademy.org › computing › computer-science › cryptography › modarithmetic › e › modulo-operator
Modulo operator (practice) | Cryptography
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Math is Fun
mathsisfun.com › definitions › modulo-operation.html
Modulo Operation (Illustrated Math Dictionary)
The modulo (or "modulus" or "mod") is the remainder after dividing one number by another.
🌐
DataCamp
datacamp.com › tutorial › modulo-operator-python
Modulo Operator in Python: Understanding Key Concepts | DataCamp
March 12, 2025 - The modulo operator (%) in Python calculates the remainder of a division operation. It follows a consistent mathematical formula:
🌐
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.
🌐
Omni Calculator
omnicalculator.com › math › modulo
Modulo Calculator
May 8, 2025 - Usually, when we use the word modulo, we mean the modulo operation, like, e.g., 11 mod 3 equals 2 — so it's simply finding the remainder. In a strict definition, the modulo means: With respect to the specified modulus. ... A is the same as B modulo C, except for differences accounted for or explained by C. Which is the definition we wrote about in the congruence modulo paragraph. However, modulo is not only used in a mathematical context.
🌐
Real Python
realpython.com › python-modulo-operator
Python Modulo Operator (%): How to Use Mod in Python – Real Python
April 1, 2023 - Well, as it turns out, not all modulo operations in Python are the same. While the modulo used with the int and float types will take the sign of the divisor, other types will not. You can see an example of this when you compare the results of 8.0 % -3.0 and math.fmod(8.0, -3.0):