Associated Topics || Dr. Math Home || Search Dr. Math

### Counting Digits

```
Date: 03/13/2002 at 16:31:09
From: Susan Diana Powers
Subject: Counting digits

I need to know how many times each digit appears when counting from 1
to 1000 and 10000 (including zeros; for instance, 0001 has three
zeros and one one).  I know that each digit appears twenty times when
counting from 1 to 100, just from a trivia question I read somewhere
once.  I don't know how to figure this out myself without actually
writing out the numbers and counting digits, or without just
approximating or guessing: for example, I'm guessing each digit
appears 300 times between 1 and 999, but again, it's just a guess.
Is there a formula for calculating the answer regardless of how many
places we're discussing (10, 100, 1000, 10000, 100000 . . . )?

Thanks for any help!
```

```
Date: 03/14/2002 at 00:15:16
From: Doctor Twe
Subject: Re: Counting digits

Hi Susan - thanks for writing to Dr. Math.

The key here is finding a pattern. Let's look at the numbers 1 to 100:

01
02
03
04
05
06
07
08
09
10
11
12
13
:
97
98
99

Let's first consider just the units digits. There's a pattern here
that repeats over and over: 1, 2, 3, ..., 9, 0, and so on. Since there
are 100 units digits, and 10 digits in the repeating pattern, each
digit appears in the units digit 100/10 = 10 times.

Now let's consider only the tens digits. Here, we have 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ..., 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 0. With the exception of that last zero, none of the digits
appears in the list once we've "passed it." There are 10 ones (from
the numbers 10-19), 10 twos (from the numbers 20-29), etc. The zeroes
are a bit different because the string starts with only 9 of them
(from the numbers 01-09), but we get a 10th one at the very end of the
list (in the number 100). So each digit appears in the tens digit 10
times.

Adding these together, we see that each digit appears in the sequence
20 times. Oops! We forgot to count the 1 in the hundreds digit of 100.
So there are really 21 ones, and 20 of each of the other digits. (I
suspect that your trivia question was really stated as the number of
times each digit appears in the range 00-99, not 01-100.)

Does this give you some insight as to how to answer the questions?

I hope this helps. If you have any more questions, write back.

- Doctor TWE, The Math Forum
http://mathforum.org/dr.math/
```
Associated Topics:
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
Math Forum Home || Math Library || Quick Reference || Math Forum Search