Home Previous: Using clickers for peer review... Next: Flipping the college classroom

# Math Monday: What is casting out nines?

September 19, 2011, 8:00 am

http://www.flickr.com/photos/artnoose/

Last week in this post, I asked for requests for math topics you’d like to read about. One person wrote in and asked:

Why don’t you enlighten us about the name “Casting Out Nines?” I learned a system in grade school with the same name –it was a way of checking multiplication and long division answers. Long before calculators.

OK then. Casting out nines is an old-fashioned method of checking for errors in basic arithmetic problems (addition and subtraction too, not just multiplication and division). Here’s how it works, using addition as an example.

Let’s suppose I’m trying to add 32189 to 87011. I get a sum of 119200. But did I make a mistake? Do the following to check:

1. Take the first number, 32189, and remove — “cast out” — any 9′s in the number and any group of numbers that adds up to 9. So, here, cast out the 9 and the pair consisting of 8 and 1. The leftover digits are 3 and 2; add those together: 3+2 = 5.
2. Do the same for the second number. For 87011, cast out the 8 and one of the 1′s (because they add up to 9). Adding the leftover digits, we get 7 + 0 + 1 = 8.
3. Now add the two sums from steps 1 and 2 together: 5 + 8 = 13. If the sum is bigger than 9, like it is here, subtract 9 from it until you get something between 0 and 8. Here, we’d subtract once: 13 – 9 = 4.
4. Finally, go to the sum I first calculated — 119200 — and cast out any nines. In this case, cast out the one 9 you see. Then add up the remaining digits: 1 + 1 + 2 + 0 + 0 = 4.

The result from step 3 should equal the result from step 4. In this case, it does. Had I obtained a different number in step 3 than I did in step 4, it would tell me I had made an error in my original adding. For example, let’s suppose made the mistake of adding the ten-thousands digits incorrectly, getting 3 + 8 = 12 and an answer of 129200 instead of 119200. Casting out the nine and adding the remaining digits would give 1 + 2 + 2 + 0 + 0 = 5, which is different than the 4 I got in step 3 — and casting out nines detects that an error has been made.

This method works also for addition, multiplication, and division (therefore you can use it for checking decimal arithmetic, not just integer) and is apparently as old as the hills. Even so, many of today’s modern check-digit systems for verifying numerical data, such as credit card numbers or UPC symbols, are based on techniques not far removed from casting out nines.

Casting out nines does have limitations. It can give false positives in some circumstances. For instance, if in the example above, I had forgotten to carry the “1″ when adding the units digits of those two five-digit numbers, I would have gotten a wrong answer of 119290. But when you cast out the two nines and add the digits, you end up with 1 + 1 + 2 + 0 = 4 which agrees with the sum of the leftovers in step 3. So step 3 equalling step 4 does not mean you did your arithmetic right. Casting out nines also fails to detect digit transpositions — if you accidentally wrote the sum down as 112900 instead of 119200, you’d still end up with a “4″ in step 4, and casting out nines would miss the error.

So, why does this method work? It’s based on the fact that given an integer, both the integer and the sum of its digits always have the same remainder when divided by 9. This is easy to see if you look at a generic integer $$N$$ of a fixed size, say three digits. Such an integer can be written as

$$N = 1000d_3 + 100d_2 + 10d_1 + d_0$$

where $$d_3, d_2, d_1$$, and $$d_0$$ are integers between 0 and 9 (and $$d_3$$ does not equal 0). Just split off one term of $$d_3, d_2$$, and $$d_1$$ and rewrite:

$$N = 999d_3 + 99d_2 + 9d_1 + (d_3 + d_2 + d_1 + d_0)$$

If you divide both sides of this equation by 9,  you will get the same remainder on the left as you do on the right because the $$999d_3 + 99d_2 + 9d_1$$ is divided evenly by 9. Nothing really changes if you use a larger integer — you would just have more terms of 9′s on the right side of the equation above and additional digits.

In more technical language, we’d say that $$N$$ and its digit sum are congruent modulo 9.  If we are adding two integers $$N$$ and $$M$$, then the digit sum of $$N+M$$ is congruent modulo 9 to the sum of the digit sum of $$N$$ and the digit sum of $$M$$. If you make a mistake in calculating $$N+M$$, this is likely to trickle down to its residue mod 9 and be detected. (But not always.)

So I called my blog “Casting Out Nines” primarily because I thought the phrase had a cool, math-y ring to it. (There’s an algebra pun there for those who know where to look.) But I also liked the blog being associated with a method of error detection, because I feel like my blogging in some ways is a form of detecting (and hopefully correcting) errors in my own work and in the world at large. And I like the fact that casting out nines has its roots (see? another math pun) in algebra and number theory, two disciplines that are close to  my heart; and yet it’s also simple enough for a child. That’s also something that I aspire to in my teaching and blogging.

Thanks for the question! Please put any more requests, corrections, expansions, etc. in the comments.

This entry was posted in Abstract algebra, Casting Out Nines, Crypto, Math, Number theory and tagged , , , . Bookmark the permalink.

• The Chronicle of Higher Education
• 1255 Twenty-Third St, N.W.
• Washington, D.C. 20037