Modular Arithmetic: from Clock Time to High Tech

You may never have heard of modular arithmetic, but you use it every day without the slightest difficulty. In this system, numbers wrap around when they reach a certain size called the modulus; it is the arithmetic of remainders [TM126 or search for “thatsmaths” at].


We use modular arithmetic for timekeeping with a 12-hour clock [Image Wikimedia Commons]

When reckoning hours, we count up to twelve and start again from one. Thus, four hours after 9 o’clock it is 1 o’clock. Numbers that differ by a multiple of the modulus 12 are said to be congruent modulo 12.

A similar situation arises for the days of the week, which are computed modulo 7. Suppose today is Thursday. What weekday will it be 1000 days from today? We don’t have to count through the thousand days, just calculate the remainder when 1000 is divided by 7, which is 6. Then the weekday 1000 days from today will be the same as in 6 days, a Wednesday.

It is much the same for other time-measurements. With 52 weeks in a year, the week number is reset to 1 at the beginning of each year, so it is confined to the range 1 to 52. Likewise, for the months, we use modulo 12 arithmetic.

The Prince of Mathematicians

Modular arithmetic was introduced by Carl Friedrich Gauss on the very first page of his magnum opus ‘Arithmetical Investigations’, or Disquisitiones Arithmeticae. Gauss was one of the most brilliant mathematicians of all time. His genius became evident at an early age. His primary school teacher set a task for the class: hoping for some peace, he asked his pupils to add up the first 100 numbers. While his class-mates attacked the problem head on, Gauss, who was just eight years old, spotted a pattern that led directly to the answer. He paired 1 with 100, 2 with 99 and so on to 50 with 51. Since each of the 50 pairs added to 101, the grand total must be 5050. Gauss gave this correct answer within a minute or so, thwarting the teacher’s plan.

Historians have not recorded the reaction of the teacher, but he might have gained some respite by asking Gauss for the product that results when the first hundred numbers are multiplied, a number called factorial 100, having 158 digits!

Disquisitiones Arithmeticae was completed when Gauss was aged only 21, and published three years later in 1801. This work revolutionized number theory, bringing together many previous results and containing much that was original. It was one of the last mathematical texts to be written in Latin. The logical structure of this book set a standard that was followed in many later texts. Gauss’s work extended the theory of numbers in several directions, and its influence continued into the 20th century.

Practical Applications

Modular arithmetic is used extensively in pure mathematics, where it is a corner-stone of number theory. But it also has many practical applications. It is used to calculate checksums for international standard book numbers (ISBNs) and bank identifiers (IBAN numbers) and to spot errors in them. Modular arithmetic also underlies public key cryptography systems, which are vital for modern commerce. It is also widely used in computer science. Finally, in music theory, modulo 12 arithmetic is used to analyze the twelve-tone equal temperament system, when notes separated by an octave of twelve semi-tones are treated as equivalent. 

Continued in next post: More on Moduli.

Last 50 Posts