Permutation & Combination Calculator
Last updated: 19 August 2026
Reviewed by Gavin · Research and drafting assisted by AI
Compute permutations P(n, r) = n! / (n − r)! and combinations C(n, r) = n! / (r! · (n − r)!) — the two formulas at the heart of counting arrangements versus selections. Pick the ordered toggle when order matters (race finishes, PIN codes), and the unordered toggle when it doesn't (lottery tickets, poker hands, committee picks). For n ≥ 21 the arithmetic switches to BigInt so very large counts stay exact.
Step-by-step
| P(n, r) = | 5 × 4 × 3 = 60 |
Comparison: P vs C for this (n, r)
| Quantity | Value | Ratio P ÷ C |
|---|---|---|
| P(5, 3) | 60 | 6 |
| C(5, 3) | 10 |
BigInt to keep the factorial exact.Permutation & Combination Calculator, nPr, nCr
What this tool does
This page computes two of the most common counting functions in combinatorics: permutations P(n,r), the number of ways to arrange r items chosen from n distinct items when order matters, and combinations C(n,r), the same count when order does not matter. The calculator supports non-negative integer n and r with 0 ≤ r ≤ n, switches between ordered and unordered with a single toggle, and uses BigInt precision for large values where JavaScript's standard Number type would lose accuracy.
The difference between permutations and combinations is the most common stumbling point in elementary probability and statistics. Permutations count ordered arrangements (like seating 10 guests at a table, or the order in which a horse race finishes), while combinations count unordered selections (like a poker hand, where the 5 cards you hold matter but not the order they were dealt). Many classical probability puzzles (lottery odds, poker hand probabilities, birthday problem, password strength) reduce to a permutation or combination calculation, and getting the formula right is the whole problem.
How to use this calculator
- Enter n (the total number of items) in the first input.
- Enter r (the number being chosen) in the second input. The constraint is 0 ≤ r ≤ n.
- Choose the mode with the toggle: "Permutations (order matters)" or "Combinations (order does not matter)".
- Click Calculate (or press Enter). The result, formula, and step-by-step working appear in the result panel.
- Use the symmetry hint when r > n/2: C(n,r) = C(n,n-r). This is the most useful optimization for combinations (you compute the smaller of the two).
- Try the quick-load buttons for common scenarios (poker hands, lottery odds, password combinations).
- Copy the result with the copy button to paste into spreadsheets or code.
Algorithm, Permutation
A permutation P(n,r) is the number of ways to arrange r distinct items chosen from n. The formula is:
P(n,r) = n! / (n-r)!
where n! is the factorial of n (the product 1 × 2 × ... × n) and (n-r)! is the factorial of n-r. Equivalently:
P(n,r) = n × (n-1) × (n-2) × ... × (n-r+1)
This is a falling factorial: the first slot can be any of n, the second any of n-1, ..., the r-th any of (n-r+1). The product has r factors. P(n,0) = 1 (the empty arrangement is unique); P(n,n) = n! (selecting all items, the only arrangement of all n items).
Edge cases:
- P(n,0) = 1 (empty selection)
- P(n,1) = n (single item selection)
- P(n,n) = n! (full arrangement)
- P(n,r) = 0 when r > n (impossible)
Algorithm, Combination
A combination C(n,r) is the number of ways to choose r distinct items from n when the order does not matter. The formula is:
C(n,r) = n! / (r! × (n-r)!)
This is the same as P(n,r) / r!, the number of ordered arrangements divided by the number of ways to arrange the r chosen items (r! permutations), since each unordered selection corresponds to exactly r! permutations. This relationship is fundamental: P(n,r) = C(n,r) × r!.
C(n,r) is also called the binomial coefficient and written (n choose r) or ⁿCᵣ in many textbooks. It appears throughout combinatorics, probability, and algebra (as the coefficients of (a+b)^n in the binomial theorem).
Symmetry identity: C(n,r) = C(n, n-r). This means you only need to compute the smaller of the two. For example, C(20, 18) = C(20, 2) = 190. The calculator hints at this when r > n/2.
Edge cases:
- C(n,0) = C(n,n) = 1 (empty selection or full selection, both unique)
- C(n,1) = C(n,n-1) = n (single item)
- C(n,r) = C(n,n-r) (symmetry)
- C(n,r) = 0 when r > n (impossible)
Worked examples
1. P(5,3) = 60
The number of ways to arrange 3 items from a set of 5 distinct items. Calculation: 5 × 4 × 3 = 60. Equivalently, 5! / 2! = 120 / 2 = 60.
2. C(5,3) = 10
The number of ways to choose 3 items from 5. Calculation: 5! / (3! × 2!) = 120 / (6 × 2) = 10. Equivalently, P(5,3) / 3! = 60 / 6 = 10. The 3 items chosen from 5 have 6 different orderings each, so the unordered count is 60 / 6 = 10.
3. P(10,3) = 720
10 × 9 × 8 = 720. The number of ways to award gold, silver, and bronze medals among 10 athletes.
4. C(10,3) = 120
10! / (3! × 7!) = 120. The number of ways to choose 3 lottery numbers from 10. By the symmetry identity: C(10,3) = C(10,7) = 120.
5. C(52,5) = 2,598,960
The number of distinct 5-card poker hands from a standard 52-card deck. Calculation: 52! / (5! × 47!) = 2,598,960. The probability of a specific hand (e.g., a royal flush) is 4 / 2,598,960 ≈ 1.54 × 10^-6.
6. P(49,6) = 10,068,347,520
The number of distinct 6-number selections in a "6/49" lottery if order mattered. In a real 6/49 lottery, order does not matter (you only need to match the 6 numbers, not the order), so the actual odds are C(49,6) = 13,983,816.
7. Edge case: P(5,0) = 1
The empty selection has exactly one arrangement (the empty arrangement). Similarly C(5,0) = 1.
8. Edge case: C(5,5) = 1
Choosing all 5 items yields exactly one set. Symmetric with C(5,0) = 1.
9. Large: C(100,50) ≈ 1.009 × 10^29
The "central binomial coefficient" of order 100. This is the largest single binomial coefficient for n = 100, and it requires BigInt arithmetic for exact computation. JavaScript Number would round it incorrectly; BigInt gives the exact 30-digit value.
Where permutations and combinations show up
- Poker hands, C(52,5) = 2,598,960 distinct 5-card poker hands; the probability of each hand type (straight flush, four of a kind, etc.) is its count divided by this total.
- Lottery odds, C(49,6) = 13,983,816 in 6/49 lotteries; C(50,5) for 5/50 "Mega Millions"-style games; P(n,k) for horse-race-style ordered-pick lotteries.
- Birthday problem, the probability of all-different birthdays in a room of k people is 365 × 364 × ... × (365-k+1) / 365^k = P(365,k) / 365^k.
- Password strength, for a password of length L over an alphabet of size A, the number of distinct passwords is A^L (not a permutation, but related). Permutations count distinct arrangements of distinct symbols.
- Sampling in statistics, hypergeometric distributions use C(n,k) for the probability of drawing k successes from n items in a finite population without replacement.
- Combinatorial genetics, the number of distinct genotypes from a gene with k alleles in a diploid organism is C(k+1,2) (or C(k,2) + k if we exclude self-pairs); the number of distinct genotypes in a Hardy-Weinberg population uses binomial coefficients.
- Probability theory, the binomial distribution P(X=k) = C(n,k) × p^k × (1-p)^(n-k) is the foundation of hypothesis testing for proportions.
- Group theory, the number of subgroups of order k in a symmetric group S_n is related to Stirling numbers of the first kind, which are sums of falling factorials (permutations of subsets).
- Combinatorial identities, Pascal's triangle (C(n,k) = C(n-1,k-1) + C(n-1,k)), Vandermonde's identity, and many other identities are proved using combinatorial reasoning.
- Algorithms, counting the leaves in a binary tree of depth d is related to C(d, k) for various k; counting subsets in a power set is 2^n = sum of C(n,k) for k from 0 to n.
Common mistakes
- Confusing permutations with combinations. If the question asks "in how many orders can X happen," use permutations. If it asks "how many distinct sets" or "in how many ways can X happen (without caring about order)," use combinations. The classic error: lottery draws use combinations (you only need to match the set of 6 numbers, not the order).
- Trying to use Number for large values. C(100, 50) requires BigInt; Number rounding gives wrong results above 2^53.
- Ignoring the symmetry identity C(n,r) = C(n, n-r). When r > n/2, the calculator uses the smaller r. Computing C(100, 99) is trivial (= 100) using symmetry; computing it directly would still work but is wasteful.
- Trying r > n. Both P(n,r) and C(n,r) are zero (or undefined) when r > n, you cannot choose 7 items from a set of 5. The calculator flags this as invalid input.
- Forgetting r! in the combination formula. Many students write C(n,r) = n! / (n-r)!, this is actually P(n,r), not C(n,r). The full formula is C(n,r) = n! / (r! × (n-r)!) or equivalently P(n,r) / r!.
- Confusing "with replacement" and "without replacement." P(n,r) and C(n,r) count selections without replacement (each item appears at most once). For selections with replacement, use r^n instead, a different formula entirely.
- Thinking the order of a poker hand matters. When you draw 5 cards, the 5-card poker hand is the unordered set; C(52,5) is correct, not P(52,5) (which would give 311,875,200, wrong for hands but correct for race finishes).
- Using permutations for password counting. A password of length L over an alphabet of size A has A^L distinct values, not P(A,L), because each position in the password is independent and characters can repeat.
Frequently Asked Questions
When do I use permutations versus combinations? Use permutations when order matters (race finishes, password attempts where order is significant, seating arrangements, ordered picks). Use combinations when order does not matter (poker hands, lottery numbers, committee selections, items in a shopping cart). The rule of thumb: if changing the order creates a new arrangement, you need permutations; if changing the order still gives the same selection, you need combinations.
What is the formula for permutations and combinations? P(n,r) = n! / (n-r)! = n × (n-1) × ... × (n-r+1). C(n,r) = n! / (r! × (n-r)!) = P(n,r) / r!. Both require 0 ≤ r ≤ n.
What is the relationship between P(n,r), C(n,r), and r!? P(n,r) = C(n,r) × r!. Each unordered combination of r items has exactly r! permutations (the number of ways to arrange those r items in a row), so converting combinations to permutations multiplies by r!.
How does the calculator handle large values? For values up to about C(60, 30), the calculator uses JavaScript Number (exact up to 2^53 ≈ 9 × 10^15, which is enough for most everyday problems). Beyond that, it switches to BigInt for exact arithmetic. The result is displayed with comma-grouped digits for readability.
What does C(n,r) = 0 mean? It means the input is invalid: r > n. You cannot choose more items than are available. The calculator flags this case before computing.
What is the binomial coefficient identity C(n,r) = C(n-1,r-1) + C(n-1,r)? This is Pascal's rule, the basis of Pascal's triangle. It states that choosing r items from n is the same as either (a) including the first item and choosing r-1 more from the remaining n-1, or (b) excluding the first item and choosing all r from the remaining n-1. The identity is exact and is the foundation for many binomial-coefficient proofs.
What is the largest C(n,r) for a given n? The largest binomial coefficient for n is the central one: C(n, ⌊n/2⌋). For even n, C(n, n/2) is the unique maximum. For odd n, C(n, (n-1)/2) = C(n, (n+1)/2) are tied. C(100, 50) ≈ 1.009 × 10^29 is the central coefficient for n = 100.
What is C(52,5)? 2,598,960, the number of distinct 5-card poker hands from a standard 52-card deck. This is the denominator in any "what is the probability of [specific hand]" poker calculation. The four-of-a-kind count is 624, so the probability is 624 / 2,598,960 ≈ 0.024%.
What is C(n,0)? C(n,0) = 1 by convention (the empty selection is unique). This is why the first column of Pascal's triangle is always 1. Similarly C(n,n) = 1 (selecting all items is unique).
What is the connection to (1+x)^n? The binomial theorem states that (a+b)^n = Σ C(n,k) × a^(n-k) × b^k for k from 0 to n. The coefficients C(n,k) are exactly the binomial coefficients. So (1+x)^n = Σ C(n,k) × x^k, and 2^n = (1+1)^n = Σ C(n,k) for k from 0 to n (the sum of all binomial coefficients for fixed n).
How does this relate to probability distributions? The binomial distribution P(X=k) = C(n,k) × p^k × (1-p)^(n-k) is the foundation of "successes in n independent trials." The hypergeometric distribution (sampling without replacement from a finite population) is P(X=k) = C(K,k) × C(N-K, n-k) / C(N,n). Both depend on combinations.
References
- Brualdi, R. A. (2010). Introductory Combinatorics. 5th edition. Pearson. ISBN 978-0136029660. Chapter 3 covers permutations and combinations with hundreds of worked examples and exercises.
- Knuth, D. E. (1997). The Art of Computer Programming, Volume 1: Fundamental Algorithms. 3rd edition. Addison-Wesley. §1.2.5 covers binomial coefficients and Stirling numbers.
- Concrete Mathematics: A Foundation for Computer Science. Graham, R. L., Knuth, D. E., Patashnik, O. (1994). 2nd edition. Addison-Wesley. ISBN 978-0201558029. Chapter 5 covers binomial coefficients in depth.
- NIST Digital Library of Mathematical Functions (DLMF). §26.3 (Binomial Coefficients). Free at dlmf.nist.gov.
- Feller, W. (1968). An Introduction to Probability Theory and Its Applications, Vol. 1. 3rd edition. Wiley. Chapter 1 covers permutations, combinations, and the basics of counting, with extensive probability applications.
- Rosen, K. H. (2019). Discrete Mathematics and Its Applications. 8th edition. McGraw-Hill. ISBN 978-1259676512. Chapter 5 covers counting, permutations, and combinations with applications to probability.
- Pascal, B. (1653). Traité du triangle arithmétique. Original derivation of Pascal's triangle and the recurrence relation C(n,k) = C(n-1,k-1) + C(n-1,k).