Compute the number of permutations (ordered arrangements) or combinations (unordered selections) of r items chosen from a pool of n. Uses BigInt arithmetic throughout so the answer is exact at any scale — no floating-point approximation, no overflow at 20! like regular numbers would give.
The formulas
Permutations — ordered arrangements:
nPr = n! / (n − r)! = n × (n − 1) × (n − 2) × … × (n − r + 1)
That’s r consecutive descending factors starting from n. Think of picking r people for 1st, 2nd, 3rd place: n choices for gold, (n−1) left for silver, (n−2) for bronze.
Combinations — unordered selections:
nCr = n! / (r!(n − r)!) = nPr / r!
The division by r! accounts for the r! different orderings of the same selection that would be double-counted by permutations. Combinations are also called “n choose r” and written C(n, r) or $\binom{n}{r}$.
Example: poker hands
How many distinct 5-card poker hands can be dealt from a 52-card deck? Order doesn’t matter in poker, so this is nCr with n = 52, r = 5.
52C5 = 52 × 51 × 50 × 49 × 48 / (5 × 4 × 3 × 2 × 1) = 311,875,200 / 120 = 2,598,960
There are 2,598,960 distinct poker hands. For context: there are 4 possible royal flushes (one per suit) and 40 straight flushes total, which is why those hands are so rare (40 / 2,598,960 ≈ 1 in 65,000).
Example: lottery odds
UK National Lottery: draw 6 balls from 49. Single ticket has 49C6 = 13,983,816 distinct possible outcomes. Odds of winning with a single ticket: 1 in ~14 million. Knowing the number helps put lottery marketing in perspective — the expected value of a £2 ticket is near-zero regardless of the jackpot size, because the probability of winning is vanishingly small.
Example: PIN codes
How many 4-digit PINs are there? If digits can repeat (which they can in real PINs), it’s 10⁴ = 10,000. If they can’t repeat, it’s a permutation: 10P4 = 10 × 9 × 8 × 7 = 5,040. The “no repeats” version removes about half the space, so “my PIN has no repeated digits” cuts the entropy significantly — one reason security-conscious password advice is the opposite of the no-repeats rule.
Example: seating arrangements
How many ways can 8 people sit in 8 chairs? That’s 8! = 40,320 (this is nPn = n!). How many ways if there are only 3 chairs and the other 5 people stand? 8P3 = 336. If we don’t care who stands vs. sits (just which 3 we pick), it’s 8C3 = 56 — exactly 336 / 6 = 336 / 3!.
Why BigInt
Factorials grow very fast. For reference:
- 10! = 3,628,800
- 13! = 6,227,020,800 — last one representable in a 32-bit signed int
- 18! = 6,402,373,705,728,000 — last one exact in a 64-bit float (≤ 2⁵³)
- 21! = 51,090,942,171,709,440,000 — exceeds Number.MAX_SAFE_INTEGER
- 52! = 8.07 × 10⁶⁷ — the number of orderings of a 52-card deck
For anything beyond about n = 20, regular JavaScript numbers lose precision and return approximations. BigInt handles integers of any size exactly, at the cost of slower arithmetic — but at the scales we’re talking about (computing a single combination or permutation), that doesn’t matter. The tool uses BigInt throughout and formats the result with thousands separators.
The falling-factorial trick
Rather than computing n! first and then dividing by (n − r)!, the tool uses the multiplicative formula:
nPr = n × (n − 1) × … × (n − r + 1)
This loop runs r times, not n times, and never builds up the full factorial. For n = 100 and r = 5, we multiply 100 × 99 × 98 × 97 × 96 = 9,034,502,400 directly, without ever touching the 158-digit value of 100!. Same idea for combinations: multiply the r numerator terms and the r denominator terms, then divide — all BigInt, all exact.
What this tool does not do
It doesn’t handle “with replacement” — when the same item can be picked multiple times. For that you’d use n^r (ordered with replacement) or C(n + r − 1, r) (unordered with replacement, the “stars and bars” formula). This tool only handles the without-replacement case, which is the more common textbook meaning.
It doesn’t compute multinomial coefficients — distributing n items into k bins of specified sizes. That’s a generalisation of nCr to multiple groups (n! / (r₁! r₂! … rₖ!)). For that use a multinomial calculator.
It doesn’t enumerate the actual arrangements — it counts them. Generating every permutation or every combination is a different problem (and the result sets are usually too large to be useful anyway — 52C5 has 2.6 million elements). For random selection from a range without enumerating the full set, the random number generator does draws with or without replacement.
It doesn’t handle negative or non-integer n / r. Combinatorics only makes sense for non-negative integers; the tool rejects fractional and negative inputs.
It doesn’t compute binomial probabilities — P(k successes in n trials with probability p) = C(n, k) p^k (1−p)^(n−k). The tool gives you the C(n, k) piece, but the probability requires multiplying by the power terms.