4 Digit Combination Calculator: Count the Possibilities
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This 4 digit combination calculator counts the possible four-digit codes and shows how the total changes when digits can repeat or the first digit is restricted. Enter the number of available digits and whether repetition is allowed to get the count instantly.
Formula
For a code of four positions, if repetition is allowed, each position has b choices, so the count is b4. If repetition is not allowed, the choices decrease by one at each position, giving b × (b − 1) × (b − 2) × (b − 3). The calculator’s first output uses the repetition selector to choose between those formulas.
Here, b is the number of available digits, a count from 1 to 10. The repetition selector r is 2 when repetition is allowed and 1 when it is not; these are numeric option values used by the calculator, not quantities. The second output counts only codes that do not begin with zero. With repetition, that is (b − 1) × b3; without repetition, it is (b − 1) × (b − 2) × (b − 3) × (b − 4). Both outputs are counts of codes, not combinations in the strict mathematical sense where order is ignored.
Worked Example
The defaults are 10 available digits and repetition allowed. For the four-digit code count:
b4 = 104 = 10 × 10 × 10 × 10 = 10,000 codes.
For codes that cannot start with zero, there are 9 choices for the first position and 10 for each remaining position: 9 × 10 × 10 × 10 = 9,000 codes. This matches the calculator’s second output.
1. Four-Digit Code Count
The main result counts every ordered four-position code, including ones with leading zeros, such as 0042. With the default ten digits and repetition allowed, there are 10,000 possible codes. This is useful for understanding the size of a keypad or PIN code space, but it does not measure how secure any particular chosen code is.
2. Repetition-Aware Calculation
The repetition selector changes the calculation rather than merely changing how the result is described. For a four-digit code made from 0–9 without reuse, the count is 10 × 9 × 8 × 7 = 5,040; if each digit can appear repeatedly, it is 10,000. Use the no-repetition setting only when the rules genuinely forbid using a digit twice.
3. Leading-Zero Check
The second result shows the count when the first position must be nonzero, as for a four-digit number written in ordinary decimal notation. At the default settings it is 9,000, because the first digit has nine choices and each later digit has ten. A code and a number are not always treated the same: codes commonly preserve leading zeros, while a numeric value such as 0042 is simply 42.
4. Adjustable Digit Set
Change the available-digit count to model a smaller set, such as digits 1–6 on a particular lock, or all ten decimal digits. The calculator assumes the allowed symbols are distinct and that each position has the same set of choices, except for the separate leading-zero rule. It does not list the codes or account for rules such as “no adjacent repeats”; those require a different counting model.
How to Choose
First decide whether you are counting an ordered code or an unordered selection. For a lock, PIN, or sequence, order matters: 1234 and 4321 are different outcomes. This calculator is for that ordered case, despite the common phrase “combination lock.”
Next establish the rules precisely. Are zeros allowed? Can the first position be zero? Can a digit repeat? Does the code have exactly four positions, or can it be shorter? The calculator treats every result as exactly four positions and offers a separate count that excludes a leading zero, but it does not make leading zeroes invalid in the main count.
Finally, check that your digit count matches the actual permitted symbols. Ten means the decimal digits 0 through 9; a set of digits 1 through 6 has six choices. If different positions have different permitted symbols, or if there are extra restrictions, do not use the simple four-position formula without adapting it. For example, excluding a specific digit from only one position changes that position’s number of choices.
Frequently Asked Questions
How many four-digit codes are possible using 0–9?
With repetition allowed and leading zeros accepted, there are 104 = 10,000 codes. If the first digit cannot be zero, there are 9,000.
How many four-digit codes have no repeated digits?
Using all ten decimal digits, with leading zero allowed, there are 10 × 9 × 8 × 7 = 5,040. If the first digit cannot be zero, the count is 9 × 9 × 8 × 7 = 4,536.
Does a four-digit code include leading zeros?
Usually a code can begin with zero, so 0042 is four characters. Ordinary decimal numbers do not preserve leading zeros; use the no-leading-zero output when counting four-digit numbers instead.
Why is “combination” not quite the right mathematical term?
In strict counting terminology, a combination ignores order. A code or PIN is a sequence, so order matters and the relevant count is a permutation-style count, with repetition handled according to the rules.
Can this calculator count codes with extra restrictions?
Not directly. Rules such as banning consecutive identical digits, requiring a particular digit, or allowing different choices by position need a formula that explicitly accounts for those conditions.
Final Thoughts
For a reliable count, define the allowed digits, whether repeats are permitted, and whether zero can appear first. Those three details determine whether the right total is 10,000, 5,040, or another value; the calculator makes those assumptions visible so you can choose the count that matches your code rules.
Related
Formula used
in b | Available digits | digits | 10 | 1 sel r | Repetition | Not allowed=1, Allowed=2 out count | Four-digit codes | codes | r * b ^ 4 + (1 - r) * b * (b - 1) * (b - 2) * (b - 3) | 0 out first_nonzero | Codes with no leading zero | codes | r * (b - 1) * b ^ 3 + (1 - r) * (b - 1) * (b - 2) * (b - 3) * (b - 4) | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.