# How Does Modulus Divison Work

## How Does Modulus Divison Work

### Question

I don't really understand how modulus division works.
I was calculating `27 % 16`

and wound up with `11`

and I don't understand why.

I can't seem to find an explanation in layman's terms online. Can someone elaborate on a very high level as to what's going on here?

### Accepted Answer

The result of a modulo division is the remainder of an integer division of the given numbers.

That means:

```
27 / 16 = 1, remainder 11
=> 27 mod 16 = 11
```

Other examples:

```
30 / 3 = 10, remainder 0
=> 30 mod 3 = 0
35 / 3 = 11, remainder 2
=> 35 mod 3 = 2
```

### Popular Answer

Most explanations miss one important step, let's fill the gap using another example.

Given the following:

```
Dividend: 16
Divisor: 6
```

The *modulus function* looks like this:

```
16 % 6 = 4
```

Let's determine why this is.

First, perform *integer division*, which is similar to normal division, except any fractional number (a.k.a. remainder) is discarded:

```
16 / 6 = 2
```

Then, *multiply* the result of the above division (`2`

) with our *divisor* (`6`

):

```
2 * 6 = 12
```

Finally, *subtract* the result of the above multiplication (`12`

) from our *dividend* (`16`

):

```
16 - 12 = 4
```

The result of this subtraction, `4`

, the *remainder*, is the same result of our *modulus* above!

Read more... Read less...

Maybe the example with an clock could help you understand the modulo.

*A familiar use of modular arithmetic is its use in the 12-hour clock, in which the day is divided into two 12 hour periods.*

Lets say we have currently this time: **15:00**

But you could also say it is **3 pm**

This is exactly what modulo does:

```
15 / 12 = 1, remainder 3
```

You find this example better explained on wikipedia: Wikipedia Modulo Article

The simple formula for calculating modulus is :-

```
[Dividend-{(Dividend/Divisor)*Divisor}]
```

So, 27 % 16 :-

27- {(27/16)*16}

27-{1*16}

Answer= 11

**Note**:

All calculations are with integers. In case of a decimal quotient, the part after the decimal is to be ignored/truncated.

eg: 27/16= 1.6875 is to be taken as just 1 in the above mentioned formula. 0.6875 is ignored.

*Compilers of computer languages treat an integer with decimal part the same way (by truncating after the decimal) as well*

The modulus operator takes a division statement and returns whatever is left over from that calculation, the "remaining" data, so to speak, such as 13 / 5 = 2. Which means, there is 3 left over, or remaining from that calculation. Why? because 2 * 5 = 10. Thus, 13 - 10 = 3.

The modulus operator does all that calculation for you, 13 % 5 = 3.

modulus division is simply this : divide two numbers and return the remainder only

27 / 16 = 1 with 11 left over, therefore 27 % 16 = 11

ditto 43 / 16 = 2 with 11 left over so 43 % 16 = 11 too

Very simple: `a % b`

is defined as the remainder of the division of `a`

by `b`

.

See the wikipedia article for more examples.