What Is Modular Arithmetic?

Learn what modular arithmetic is, how to perform it, and how it’s used in the real world.

Jason Marshall, PhD
5-minute read
Episode #53

How to Perform Modular Addition

So that’s the idea of modular arithmetic. Now let’s talk about how to actually do it. It’s helpful here to keep the idea of a clock in mind. For arithmetic with a modulus of 12—also called arithmetic modulo 12—you can think of an actual clock that has 12 numbers on what is essentially a circular number line. For example, what’s 9 + 1 modulo 12? Well, if we think of starting at 9 on a normal 12-hour clock and then moving forward 1 hour, we find that 9 + 1 modulo 12 is just 10. In this case, since 10 is less than the modulus of 12, the answer is the same as with normal math.

But what about something like 9 + 5 modulo 12? Here, in normal non-modular arithmetic, the answer is 9 + 5 = 14. But in modular arithmetic with a modulus of 12, the numbers wrap around after we count up to 12. So to find 9 + 5 modulo 12, we need to count forward 5 hours from 9, being sure to start over once we get to 12. And when we do that we find that 9 + 5 modulo 12 is 2. In other words, using a clock to help visualize this, we start at 9 and then count forward 5 hours: 10, 11, 12, 1, and finally 2.

More Modulo Arithmetic

What if instead of modulo 12 arithmetic we want to perform modulo 5 arithmetic? For example, what’s 9 + 1 modulo 5? Well, this time you need to imagine a clock that cycles through only 5 numbers—from 0 at the top, then 1, 2, 3, and finally 4, before starting back at 0 again. (By the way, a normal 12-hour clock could just as easily start with 0 at the top instead of 12—we just don’t traditionally do it that way.) To find 9 + 1 modulo 5, we need to start at the top of this new 5 numbered clock, count forward 9 spaces, and then count forward another 1 space. Where do you end up? Well, you end up right back where you started at the top. In other words, 9 + 1 modulo 5 is 0.

[[AdMiddle]So as not to get things confused with normal (meaning non-modular) arithmetic, in modular arithmetic we don’t usually say that 9 + 1 modulo 5 is “equal” to 0. Instead we say that 9 + 1 modulo 5 is “congruent” to 0. And we write this as (9 + 1) (mod 5) ≡ 0. The word congruent here roughly means “the same as,” and we represent this idea of congruence in writing using a symbol that looks like an equals sign but with one extra horizontal line in the middle of it.

Modular Arithmetic in the Real World

Okay, that’s enough for now to get us started on our way towards understanding the ins-and-outs of this new kind of admittedly strange arithmetic. We’ll return to this topic now and again in future articles to talk about other aspects of modular arithmetic and the other ways in which it’s used in the real world. That’s right, this isn’t all just random math stuff—it actually turns out to be very useful math stuff. But we’ll talk about exactly how it’s useful in later articles.


About the Author

Jason Marshall, PhD

Jason Marshall is the author of The Math Dude's Quick and Dirty Guide to Algebra. He provides clear explanations of math terms and principles, and his simple tricks for solving basic algebra problems will have even the most math-phobic person looking forward to working out whatever math problem comes their way.