The Math Forum

Ask Dr. Math - Questions and Answers from our Archives
Associated Topics || Dr. Math Home || Search Dr. Math

What is Modulus?

Date: 06/06/2001 at 17:04:15
From: Bryan Sydnor
Subject: Modulus - Why use it, and how do you calculate it?

I am a Mechanical Engineer, and am learning to program on my own. I 
have used the mod command and know what the results mean, but I don't 
understand the theory behind it and what is actually happening. If you 
could point me to a book or Web site that would explain what the 
modulus actually is, its implications in math, and methods for solving 
it, it would be greatly appreciated.


Date: 06/07/2001 at 08:53:25
From: Doctor Peterson
Subject: Re: Modulus - Why use it, and how do you calculate it?

Hi, Bryan.

The "mod" operator in computer languages is simply the remainder. For 

    17 mod 3 = 2


    17 / 3 = 5 rem 2

which in turn means

    17 = 3 * 5 + 2

There are some tricky issues when negative numbers are used, but that 
shouldn't ordinarily be necessary.

In math (number theory), the term is used a little differently. The 
"modulus" is actually not the remainder, but the number you are 
dividing by; and "mod" is not an operator, but a label telling "in 
what sense two quantities are considered congruent, or equal." For 
example, we would say

    17 = 11 (mod 3)

(read as "17 is congruent to 11, modulo 3"), meaning that 17 and 11 
both leave the SAME remainder when divided by 3. You probably won't 
see this usage if you are only reading about programming, but it's 
worth being aware of if you look deeper into the math behind it.

Here are three references in our archives:

   Modulus Operator Problem   


   Mod Function and Negative Numbers   

If this hasn't answered all your questions, please write back and tell 
me a little more about what you are doing with "mod" and what aspects 
you don't fully understand. I can probably give you more details if I 
see what you need to know.

- Doctor Peterson, The Math Forum   
Associated Topics:
High School Calculators, Computers
High School Number Theory

Search the Dr. Math Library:

Find items containing (put spaces between keywords):
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

Math Forum Home || Math Library || Quick Reference || Math Forum Search

Ask Dr. MathTM
© 1994- The Math Forum at NCTM. All rights reserved.