21 mod 20 with+steps

What is 21 mod 20?

Modulo Calculator

Please input the dividend and divisor:

a (dividend) b (divisor)

Solution work for 'a' modulo 'b'

Modulo Operator as Used in our Calculator

This operation (or function) rounds a value downwards to the nearest integer even if it is already negative. The floor function returns the remainder with the same sign as the divisor. This is the method used in our calculator. See how it works by examples:

  • floor(2.1); // returns number 2
  • floor(2.7); // returns number 2
  • floor(-5.2); // returns number -6
  • floor(-5.7); // returns number -6

Some hints:

  • a mod 1 is always 0;
  • a mod 0 is undefined;
  • Divisor (b) must be positive.

This function is used in mathematics, where the result of the modulo operation is the remainder of the Euclidean division.

The first result in our calculator uses, as stated above, the function floor() to calculate modulo as reproduced below:

a mod b = a - b × floor(a/b)

To understand how this operation works, we recommend reading What is modular arithmetic? from Khan Academy.

The Modulo Operator (%) in Some Programming Languages Like PHP and Javascript

In computers and calculators due to the various ways of storing and representing numbers the definition of the modulo operation depends on the programming language or the hardware it is running.

For example, in PHP $a % $b means 'a' modulo 'b'. In Javascript, it is written as a % b. This symbol '%', in both languages, is called modulo operator. It simply returns the remainder of 'a' divided by 'b'. That explains the differences found in the calculator when 'a' (dividend) is negative and b isn't equal to 1. It is because a mod b isn't simply the remainder as returned by the operator '%'. See some examples:

Operation a mod b $a % $b
5 mod 3 2 2
3 mod 1 0 0
-5 mod 3 1 -2
-3 mod 5 2 -3
15 mod 12 3 -3
29 mod 12 5 5
-4 mod 12 8 -4
-13 mod 6 5 -1


There are some other definitions in math and other implementations in computer science according to the programming language and the computer hardware. Please see Modulo operation from Wikipedia.

Modulo Operation by Exmaples


While every effort is made to ensure the accuracy of the information provided on this website, neither this website nor its authors are responsible for any errors or omissions. Therefore, the contents of this site are not suitable for any use involving risk to health, finances or property.