Take the 2-minute tour ×

I understand the Modulus operator in terms of the following expression:

7 % 5

This would return 2 due to the fact that 5 goes into 7 once and then gives the 2 that is left over, however my confusion comes when you reverse this statement to read:

5 % 7

This gives me the value of 5 which confuses me slightly. Although the whole of 7 doesn't go into 5, part of it does so why is there either no remainder or a remainder of positive or negative 2?

If it is calculating the value of 5 based on the fact that 7 doesn't go into 5 at all why is the remainder then not 7 instead of 5?

I feel like there is something I'm missing here in my understanding of the modulus operator.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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

Modulus gives the remainder of the division of one number by another. If you ask to a 8 years old kid what 5 divided by 7 gives (8 because they mostly don't know decimal numbers), he will answer: 0 but it remains 5.

You can also use this equation:

a % b = a - floor(a / b) * b

floor(a / b) represents the number of times you can divide a by b (see for example the illustration below). And floor(a / b) * b the amount that was successfully shared entirely. Which means that the total minus what was shared equals the remainder of the division. Now you can use this equation:

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

Euclidian Division

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 it's 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.

share|improve this answer

Modulus operator gives you the result in 'reduced residue system'. For example for mod 5 there are 5 integers counted: 0,1,2,3,4. In fact 19=12=5=-2=-9 (mod 7). The main difference that the answer is given by programming languages by 'reduced residue system'.

share|improve this answer

A novel way to find out the remainder is given below

Statement : Remainder is always constant

ex : 26 divided by 7 gives R : 5 

this can be found out easily by finding the number that completely divides 26 which is closer to the divisor and taking the difference of the both

13 is the next number after 7 that completely divides 26 because after 7 comes 8, 9 ,

10, 11, 12 where none of them divides 26 completely and give remainder 0.
So 13 is the closest number to 7 which divides to give Remainder 0.
now take the difference (13 ~ 7) = 5 which is the Remainder .

note : for this to work divisor should be reduced to its simplest form ex: if 14 
is the divisor ..7 has to be chosen to find the closest number dividing the dividend.
share|improve this answer

Your Answer


