Counting digit strings with and without an initial zero
Four decimal positions give 10,000 strings if a leading zero is allowed and 9,000 if it is not. The difference comes entirely from the first position.
Counting by position
To count strings of a fixed length, choose each position in turn and multiply the number of choices. A four-position decimal string has ten choices for each of the four positions, so there are 10 × 10 × 10 × 10 = 10⁴ = 10,000 strings, from 0000 to 9999. This is the multiplication principle: when choices at each position are independent, the total is the product of the counts. The power calculator returns 10,000 for base 10 and exponent 4, which matches the first worked case. The result includes strings such as 0000, 0042 and 0999, which begin with a zero.
Removing the zero from the first position
If the string has to be an ordinary four-digit positive integer, the first digit cannot be zero. It has nine choices, 1 through 9, and each of the other three positions still has ten choices. The count is 9 × 10 × 10 × 10 = 9,000. These are the integers 1000 through 9999. A direct check is 9999 - 1000 + 1 = 9,000. The basic calculator returns 9,000 for 9 × 1000. Another check is the complement: 10,000 - 9,000 = 1,000, which is the number of strings from 0000 to 0999 that start with a zero.
Why the other positions are unchanged
Only the first position carries the restriction. The second, third and fourth can be any digit from 0 to 9, even if they are zero, as in 1000, 2005 or 9990. So the number of choices at those positions stays at ten. People sometimes subtract the restriction from every position by mistake and reach 9⁴ = 6,561, which excludes any zero at all and answers a different question: four-digit strings with no zero digit anywhere. Keeping track of which position each rule applies to is the main skill in these counts.
A six-position identifier
Consider a six-digit code. If zeros are allowed anywhere, there are 10⁶ = 1,000,000 codes, from 000000 to 999999. If the code must be a six-digit integer, the first digit has nine choices and the count is 9 × 10⁵ = 900,000. For a three-digit code the counts are 1,000 and 900. In general a string of length n has 10^n possibilities when leading zeros are allowed, and 9 × 10^(n-1) when they are not. The ratio of the two counts is always 10 to 9, so ten percent of the all-strings total is lost whatever the length.
Strings versus integers
The string 0007 has four positions, but as a number it is seven. Many systems that store identifiers as numbers drop leading zeros, which can turn a postal code or part number such as 02134 into 2134. When you need the leading zeros to survive, store the identifier as text, or pad it to the field width whenever it is displayed. A counting question about labels, such as how many four-position codes exist, is about strings. A counting question about numbers is about values, and 0007 and 7 are the same value. Deciding which one a problem means decides which count applies.
Other bases and alphabets
The same logic works for any alphabet. Four-position hexadecimal strings have 16⁴ = 65,536 possibilities. If the first digit may not be zero, it has 15 choices and the count is 15 × 16³ = 61,440. For binary strings of length 8, there are 2⁸ = 256 strings, and 128 of them start with 1. Four-letter strings from a 26-letter alphabet number 26⁴ = 456,976. The idea is the same in each case: count the choices for the restricted position, then multiply by the full alphabet size for the others. Changing the base changes the numbers but not the method.
Label formats and further position rules
Label formats make the difference practical. A system that issues four-digit PINs as text has 10,000 possible values, while one that treats them as integers from 1000 to 9999 has 9,000. Product codes, ticket numbers and apartment numbers each follow one rule or the other. When a spec says four-digit number, it may or may not allow a leading zero, so the spec should state it. The counts also serve as a check on database field sizes, since a column designed for 9,000 values is too small if the application also issues codes beginning with zero. Other position rules follow the same multiplication. Four-position strings with no zero in any position number 9⁴ = 6,561. Strings whose last digit must be even have five choices in that position and so number 10 × 10 × 10 × 5 = 5,000 when zeros may lead. Strings whose first digit is nonzero and whose last digit is even number 9 × 10 × 10 × 5 = 4,500. Each added restriction replaces the ten at one position with the number of allowed digits there. Because the positions stay independent, the count never needs more than a single product, as long as each rule affects only one position. Rules that tie two positions together, such as no repeated digits, require a different count.
Counting strings with a fixed number of digits at each position
A useful companion count asks how many four-position strings use only digits from a smaller set. If only the digits 0 and 1 are allowed, each position has two choices and there are 2⁴ = 16 strings, which is the same as the number of four-bit binary patterns. If the allowed set is the eight digits 0 through 7, there are 8⁴ = 4,096 strings. Requiring a nonzero first digit changes the first factor from 8 to 7, giving 7 × 8³ = 3,584. Each time, the structure is the same as the main example: one factor per position, with the first factor reduced when the leading zero is banned. The power calculator handles the all-strings version, and a short multiplication handles the restricted one.
What the label counts leave out
The counts here describe the number of possible labels, and nothing more. They say nothing about how secure a code is, how a code should be generated or how likely a guess is to succeed. Real codes often exclude patterns such as 0000, and users do not choose uniformly. A random choice among 10,000 strings has a one in 10,000 chance of any given value, but human-chosen strings cluster, so the count is an upper bound on variety, not a measure of strength. The worked cases use whole-number powers that the calculator evaluates exactly. For the lengths used here, every count fits easily within the range where ordinary arithmetic is exact. A string count with more than fifteen decimal positions would exceed the range where a floating-point display shows every digit, and an exact integer tool would be needed.
Reproduce the checks
All four-position strings
Open the Power calculator and enter:
- Base
10- Exponent
4
Expected output:
Power
10000Every position has ten permitted digits.
Nonzero initial digit
Open the Basic calculator and enter:
- First number
9- Operation
multiply- Second number
1000
Expected output:
Result
9000Only the first position loses its zero choice.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.