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 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
2 weeks 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โ€ ...
๐ŸŒ
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.
๐ŸŒ
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).
๐ŸŒ
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
๐ŸŒ
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:
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
Omni Calculator
omnicalculator.com โ€บ math โ€บ modulo-order-of-operations
Modulo in the Order of Operations
October 4, 2025 - The modulo operator returns the remainder of the division of one number by some other number. Remember, we're dealing with integer numbers here. In mathematical notation, if a and n are two integers, we can always find b and r such that
๐ŸŒ
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):