Explanation of Mathematics




Explanation of Mathematics

Modular arithmetic is “arithmetic done with a count that resets itself to zero every time a certain whole number N greater than one, known as the modulus (mod), has been reached” (Berggren, 2025, para. 1). In essence, the idea is that numbers wrap around once they reach the modulus, like a clock. When we use modular arithmetic, we are referring to an idea of congruence between integers. This idea of congruence was pioneered by Leonhard Euler, a Swiss mathematician. He “explicitly introduced the idea of congruence modulo a number N and showed that this concept partitions the integers into N congruence classes, or residue classes” (Berggren, 2025, para. 4). For any number N, the congruence classes, also known as “residues modulo N” are [0], [1], [2],…,[N-1] which represent the possible remainders when dividing an integer by N (Berggren, 2025). For example, if N=5, the congruence classes would be [0], [1], [2], [3], and [4]. All numbers will fit into one of these congruence classes. To find which congruence class a number is a part of you subtract the modulus until you end up at a number in the range of 0 to N-1, or find the remainder when dividing by N. For example, if you want to find the congruence class that 14 fits into in mod 5, you could do 14 – 5 – 5 = 4 or 14/5 = 2 remainder 4. Both solutions tell you that 14 fits into the congruence class of [4] in mod 5. Carl Friedrich Gauss introduced the notation we use today to denote congruence between two numbers a and b in mod n. We denote congruence as follows: a ≡ b(mod n), read as “a is congruent to b mod n” (Berggren, 2025). When two numbers are congruent mod n, they are part of the same congruence class. In our example, we would write: 14 ≡ 4(mod 5), which means that 14 and 4 are in the same congruence class in mod 5. Another way to determine congruence between numbers in mod n is by looking at their difference. We can tell that “Two integers are in the same congruence class modulo N if their difference is divisible by N” (Berggren, 2025, para. 4). We can see this applied in our ongoing example. The difference between 14 and 4 is 10, and 10 is divisible by 5, thus 14 and 4 are in the same congruence class. We can perform addition, subtraction, multiplication, and exponentiation using modular arithmetic. The idea is almost the same as “regular” arithmetic, but our solution is always one of the congruence classes: [0],…,[N-1]. Consider doing arithmetic in modulo 7, one way we can solve these problems is by imagining a clock with seven numbers. For example, “To add 3 and 5 modulo 7, you start at 0, count 3 clockwise, then a further 5 clockwise, this time ending on 1. To multiply 3 by modulo 7, you start at 0 and count 3 clockwise 5 times, again ending up at 1. We would write 3 + 5 ≡ 1 (mod 7) and 3 * 5 ≡ 1 (mod 7)” (Taylor, 2012, para. 5). When visualizing is difficult or unreasonable, perform regular arithmetic, divide by N, and the remainder will be your solution. For example, to solve 5 * 21 in mod 6, I would do 5 * 21 = 105, 105/6 = 17 remainder 3. So, 5*21 ≡ 3 (mod 6). See Figure 1 for an addition and multiplication table in mod 5.

Figure 1

Addition and Multiplication Tables

Consider verifying the answers to see if you understand the process. For a challenge, try making an addition and multiplication table for another modulus. Interact with the applet below to check your work!

One concept that is used in many of the applications of modular arithmetic is the idea of the modular inverse. The division operation does not exist in modular arithmetic, but the modular inverse does. Two numbers are inverses of each other in modulo n if when multiplied modulo N, their product is 1. (Kahn Academy, 2018). However, not all numbers have a modular inverse given a certain modulus. The rule is that for any number a in mod n, a and n need to be coprime to each other for the modular inverse to exist - meaning they only share the factor of 1. (Kahn Academy, 2018). See this demonstrated in Figures 2 and 3.

Figure 2

Inverse Example

Figure 3

Example of no Inverse

The modular inverse of 3 in mod 7 is 5 because 3*5 ≡ 1 (mod 7), whereas the modular inverse of 2 in mod 6 does not exist. This can be explained by the fact that 2 and 6 share the factor of 2.

For further explanation of the mathematics of modular arithmetic and more examples, refer to the following video: