About the Permutation & Combination Calculator
Combinatorics is the branch of mathematics that counts arrangements and selections of finite sets. The two foundational operations are the permutation, written nPr or P(n,r), which counts how many ordered sequences of r items you can form from n distinct objects, and the combination, written nCr, C(n,r), or "n choose r", which counts how many unordered subsets of size r you can form from the same n. These two numbers underlie probability theory, hand-evaluation in poker, lottery odds, the binomial distribution, statistical sampling, password-strength estimation, and the structure of Pascal's triangle. This calculator returns nPr, nCr, and n factorial for any non-negative integers with r at most n.
Calculation is performed in your browser. For nPr and nCr the tool uses a multiplicative algorithm that avoids overflowing on intermediate factorials, so n values up to about 170 are safe for nPr and much larger for nCr with moderate r.
How the formulas work
Factorial: n! = n · (n-1) · (n-2) · ... · 2 · 1
0! = 1 (by convention)
Permutation: nPr = n! / (n - r)!
= n · (n-1) · (n-2) · ... · (n - r + 1) [r terms]
Combination: nCr = n! / ( r! · (n - r)! )
= nPr / r!
Identity: nCr = nC(n - r)
nCr = (n-1)C(r-1) + (n-1)Cr [Pascal's rule]
The intuition: a permutation first counts ordered arrangements (n choices for first slot, n minus 1 for second, and so on, r slots total), while a combination then divides by r factorial because each unordered set was counted r factorial times in the ordered list.
Worked example: lottery vs poker
Two classic combinatorics questions, both solvable with the formulas above.
- UK National Lottery odds. Choose 6 numbers from 1 to 59. Order does not matter, so use combinations: 59C6 = 59 factorial divided by (6 factorial × 53 factorial) = 45057474. The probability of matching all six is 1 in 45 million.
- Five-card poker hand from a 52-card deck. Order in your hand does not matter: 52C5 = 2598960 total hands. The number of royal flushes is just 4 (one per suit), so the probability is 4 divided by 2598960 = roughly 1 in 650000.
- Permutation example: race podium. Eight runners compete; how many gold-silver-bronze orderings are possible? Order matters, so use permutations: 8P3 = 8 × 7 × 6 = 336.
- Sanity check with factorials. 8 factorial divided by 5 factorial = 40320 divided by 120 = 336. Matches.
Quick reference table
| n | r | nPr (order matters) | nCr (order does not matter) | Real-world scenario |
|---|---|---|---|---|
| 5 | 3 | 60 | 10 | Choose 3 from 5 friends |
| 10 | 3 | 720 | 120 | Pick 3 medals from 10 runners |
| 26 | 4 | 358800 | 14950 | 4-letter strings vs 4-letter sets |
| 52 | 5 | 311875200 | 2598960 | Poker hand orderings vs hands |
| 59 | 6 | 32441381280 | 45057474 | UK National Lottery (combinations) |
| 49 | 6 | 10068347520 | 13983816 | Old UK Lotto / Powerball variant |
Common pitfalls
- Using nPr when nCr is right (or vice versa). The first decision is always: does order matter? Lottery numbers, poker hands, committees: combinations. Passwords, podium finishes, seating arrangements: permutations.
- Repetition not handled. Standard nPr and nCr assume no repetition (each item chosen at most once). For arrangements with repetition (a 4-digit PIN from digits 0 to 9 with repeats allowed) use n to the power r, not nPr.
- Forgetting symmetry. nCr equals nC(n minus r). 10C7 is the same as 10C3 = 120, not a different calculation.
- Factorial overflow. 21 factorial overflows a 64-bit integer; 171 factorial overflows a 64-bit float. If you compute nCr by literally dividing two factorials you may hit overflow before the actual answer overflows. Use the multiplicative form r terms long.
- Confusing the binomial with the multinomial. Choosing one subset of size r from n is binomial. Splitting n into multiple groups of given sizes is multinomial, which uses n factorial divided by the product of all group factorials.
- Negative or non-integer r. nPr and nCr are only defined for non-negative integers with r at most n. The calculator returns zero for r greater than n by convention; school textbooks sometimes mark this case as undefined.
Frequently asked questions
What is the difference between permutation and combination?
A permutation counts ordered arrangements where order matters: ABC and CBA are different permutations. A combination counts unordered selections where order does not matter: ABC and CBA are the same combination. The formulas are nPr equal to n factorial divided by (n minus r) factorial, and nCr equal to n factorial divided by r factorial times (n minus r) factorial. Choosing 3 letters from a 5-letter pool gives 60 permutations but only 10 combinations, because each combination corresponds to 3 factorial equal to 6 different orderings.
What does the factorial notation n! mean?
n factorial, written n with an exclamation mark, is the product of all positive integers from 1 up to n. So 5 factorial is 5 times 4 times 3 times 2 times 1 equal to 120, and 10 factorial is 3628800. By definition 0 factorial is 1, which keeps the nCr and nPr formulas consistent for edge cases. Factorial grows extremely fast: 13 factorial overflows 32-bit signed integers, and 21 factorial overflows 64-bit signed integers. JavaScript's 64-bit float keeps n factorial exact up to 18 factorial.
When do I use permutations versus combinations?
Use permutations when sequence or position matters: arranging books on a shelf, picking 1st, 2nd, and 3rd place finishers, decoding a passcode, seating people around a table. Use combinations when only the set matters: dealing a poker hand, choosing a committee, picking lottery numbers, selecting toppings on a pizza. A useful test: if swapping two of the items produces a meaningfully different outcome, you have a permutation; if it does not, you have a combination.
What is Pascal's triangle and how does it relate to nCr?
Pascal's triangle is the triangular array of binomial coefficients. Row n (starting at 0) lists nC0, nC1, nC2, all the way to nCn. Each entry equals the sum of the two entries directly above it, which is the combinatorial identity n choose r equals (n minus 1) choose (r minus 1) plus (n minus 1) choose r. The triangle was known to Persian mathematician al-Karaji around 1007 and Chinese mathematician Yang Hui around 1261, centuries before Pascal published in 1655.
How big can n and r be before overflow?
JavaScript represents numbers as 64-bit IEEE 754 floats, which lose integer precision beyond 2 to the 53 (about 9 quadrillion). 18 factorial fits, 21 factorial does not. For binomial coefficients nCr the calculator uses the multiplicative formula r terms long, which keeps intermediate products small and lets you go to about n equal to 1000 for moderate r. Beyond that you would need an arbitrary-precision library like BigInt or a computer algebra system.
