Modulo Function (Modulus)

Calculus Definitions >


  1. Modulo Function
  2. Modulus Function

What is a Modulo Function?

The modulo function represents the remainder that results from dividing two different positive numbers. For example, 7 modulo 2 is 1 because the division of 7 by 2 has a quotient of 3, leaving a remainder of 1. Although the modulo function initially seems like an esoteric mathematical function, it does have a few practical applications including identifying odd or even numbers in worksheets, databases, or complex formulas (Bluttman & Aitken, 2018); In programming, the modulo can be used to alternate values in a loop.

The modulo function is sometimes called a modulus function. However, the term “modulus” can have many meanings (see the notes below on modulus functions); Many authors prefer modulo to modulus to avoid this confusion.

Formal Definition of Modulo Function

An arbitrary positive integer, a, can always be written in the following form

a = n * q + r



  • q is the quotient,
  • r is the remainder, and
  • n is an integer.

Within this formal definition, the modulo expression can be solved: (a mod n) = r.


Calculating the Modulo

The basic steps are:

Step 1: Set up the equation. Given the expression (a mod n), set up the equation a = n * q + r.

Step 2: Maximize the quotient, q.

Step 3: Solve for the remainder, r.

Step 4: (a mod n) = r.

Example Problems

Problem 1: Find (18 mod 5) using the formal definition of modulo.


Step 1: In the context of the formal definition, a = 18 and n = 5. Therefore,

18 = 5 * q + r


Step 2: Maximize the quotient. For this equation, q=3.

Step 3: Solve for the remainder:

  • 18 = 5 * 3 + r
  • 18 = 15 + r
  • r = 3

Therefore, (18 mod 5) = 3.


Problem 2: Find (17 mod 4) using the formal definition of modulo.

Solution: Within the formal definition of modulo, we identify that a=17 and n=4. Therefore,

17 = 4 * q + r


The maximum value for the quotient is q = 4.

Solving for the remainder,

17 = 4 * 4 + r

17 = 16 + r

r = 1


Thus, (17 mod 4) = 1.


Problem 3: Find (3 mod 1) using the formal definition of modulo.

Solution: From the formal definition of modulo, we have

3 = 1 * q + r


In this case, the maximum value of q=3.

3 = 1 * 3 + r


Solving for the remainder, r = 0. In fact, any integer modulo 1 is always equal to zero, since q=a.


Special Considerations with the Modulo Function

  • The modulo function only accepts positive natural numbers. You cannot evaluate the modulo of a negative number or a fraction.
  • The remainder can only be calculated after the quotient is evaluated correctly. If the quotient is not at its maximum value, then your calculation for the remainder will be incorrect.

Modulus Function

The term modulus is one of those unfortunate terms in mathematics that can mean a few different things, depending on where you’re using it and who the author is. The term modulus function can refer to either the absolute value function or the modulo function.

In calculus, you’ll usually be dealing with the modulus function, which is commonly used as a synonym for the absolute value function in general math (Hennings, 2017; Sherran, 1999). In complex analysis, it means something similar, but not quite the same: the modulus of z is defined as (Britannica, 2020)

“…the real number Square root of √a2 + b2, which corresponds to z’s distance from the origin of the complex plane.”

maximum modulus function
The maximum modulus function from complex analysis (Silverman, 1984):

There are a few more areas of confusion. Most notably that some authors use modulus function as a synonym for the modulo function (which is completely different from the absolute value function). The word modulus, although it’s commonly used to mean the same thing as absolute value, also crops up in modular arithmetic; It refers to the remainder operation returning the remainder of m divided by n. “Modulo” and “modulus” are often used interchangeably, with some authors (e.g. Dannenberg, 2019) calling the remainder operation the modulus function.

Another area that causes confusion: the absolute value bars “| |” are also used to indicate the modulus (or magnitude) of a vector. This is similar to the absolute value, but again, not quite the same.

Despite all of the different definitions, you can usually figure out the author’s intent by considering the big picture of they are writing about.

Why All The Different Definitions for Modulus Function?

There are a staggering number of definitions of the word “modulus”. These developed over time, some completely independent of each other (when people had to communicate by letter or telegraph, if they were able to at all!). A few more (from Jeff Miller’s Earliest Known Uses of Some of the Words of Mathematics):

  • Gauss first wrote about the term “modulo” in Disquisitiones arithmeticae (1801, p. 9)

    “If a number a measure the difference between two numbers b and c, b and c are said to be congruent with respect to a, if not, incongruent; a is called the modulus, and each of the numbers b and c the residue of the other in the first case, the non-residue in the latter case” (Miller, 2020)

  • The Oxford English dictionary defines it as

    “The positive square root of the sum of the squares of the real and imaginary parts of a complex number.”

  • The term modulus means “length of the vector a + bi”, due to Jean Robert Argand (1768-1822) (Cajori 1919, page 265).


Bluttman, K. & Aitken, P. Excel Formulas and Functions For Dummies. 2018..
Britannica. (2020). Absolute Value.
Cajori, Florian. A History of Mathematics. New York: The Macmillan Co., 1919.
Dannenberg (2019). Modulus (%) Illustrated. Retrieved November 10, 2020 from:
Gauss, F. (2009 Translation). Disquisitiones arithmeticae. Yale University Press, New Haven & London.
Hennings, M. (2017). Cambridge Pre-U Mathematics Coursebook. Cambridge University Press.
Miller, J. Earliest Known Uses of Some of the Words of Mathematics (M).
Oxford English Dictionary. Modulus. Retrieved November 10, 2020 from:
Sherran, P. (2000). Graphical Calculator Support Pack (Complete Advanced Level Mathematics). Nelson Thornes.
Silverman, R. (1984). Introductory Complex Analysis. Dover.

Comments? Need to post a correction? Please Contact Us.

Leave a Comment