Permutation & Combination Calculator
Calculate nPr (permutations) and nCr (combinations) with factorial formulas.
Back to all tools on ToolForge
Result
About Permutation & Combination Calculator
This calculator computes permutations (nPr) and combinations (nCr) using factorial formulas. Permutations count arrangements where order matters, while combinations count selections where order doesn't matter. Both are fundamental concepts in probability theory, statistics, and combinatorics.
Formulas
Permutation (nPr): nPr = n! / (n-r)! Combination (nCr): nCr = n! / (r! × (n-r)!) Where: n! = n × (n-1) × (n-2) × ... × 2 × 1 0! = 1 (by convention) Example: n=5, r=3 5P3 = 5!/(5-3)! = 120/2 = 60 5C3 = 5!/(3!×2!) = 120/(6×2) = 10
JavaScript Implementation
// Factorial function with overflow protection
function factorial(n) {
if (n < 0 || n > 170) return Infinity; // Beyond safe integer range
if (n === 0 || n === 1) return 1;
let result = 1;
for (let i = 2; i <= n; i++) {
result *= i;
}
return result;
}
// Permutation: nPr = n! / (n-r)!
function permutation(n, r) {
if (r > n || r < 0) return 0;
return factorial(n) / factorial(n - r);
}
// Combination: nCr = n! / (r! × (n-r)!)
function combination(n, r) {
if (r > n || r < 0) return 0;
return factorial(n) / (factorial(r) * factorial(n - r));
}
// Optimized combination (avoids large factorials)
function combinationOptimized(n, r) {
if (r > n) return 0;
if (r === 0 || r === n) return 1;
if (r > n - r) r = n - r; // Use symmetry: nCr = nC(n-r)
let result = 1;
for (let i = 1; i <= r; i++) {
result = result * (n - i + 1) / i;
}
return result;
}
Factorial Reference Table
| n | n! | Scientific Notation |
|---|---|---|
| 0 | 1 | 1 × 10⁰ |
| 1 | 1 | 1 × 10⁰ |
| 2 | 2 | 2 × 10⁰ |
| 3 | 6 | 6 × 10⁰ |
| 4 | 24 | 2.4 × 10¹ |
| 5 | 120 | 1.2 × 10² |
| 6 | 720 | 7.2 × 10² |
| 7 | 5,040 | 5.04 × 10³ |
| 8 | 40,320 | 4.03 × 10⁴ |
| 9 | 362,880 | 3.63 × 10⁵ |
| 10 | 3,628,800 | 3.63 × 10⁶ |
| 12 | 479,001,600 | 4.79 × 10⁸ |
| 15 | 1,307,674,368,000 | 1.31 × 10¹² |
| 20 | 2,432,902,008,176,640,000 | 2.43 × 10¹⁸ |
Permutation vs Combination: When to Use Each
| Scenario | Order Matters? | Formula | Example (n=5, r=3) |
|---|---|---|---|
| Race rankings (1st, 2nd, 3rd) | Yes | nPr | 5P3 = 60 ways |
| Committee selection | No | nCr | 5C3 = 10 ways |
| Password/PIN codes | Yes | nPr | Digits 0-9, 4 positions: 10P4 |
| Lottery numbers | No | nCr | Pick 6 from 49: 49C6 |
| Seating arrangement | Yes | nPr | 5 people, 3 seats: 5P3 |
| Pizza toppings | No | nCr | Choose 3 from 10: 10C3 |
Worked Examples
Example 1: Arranging Books on Shelf Q: How many ways to arrange 3 books from 5 different books? A: Order matters (book positions differ), so use permutation. 5P3 = 5!/(5-3)! = 120/2 = 60 ways Example 2: Selecting Team Members Q: How many ways to select 3 players from 5 players? A: Order doesn't matter (team is same regardless of selection order). 5C3 = 5!/(3!×2!) = 120/(6×2) = 10 ways Example 3: Lottery Probability Q: In a lottery picking 6 numbers from 49, what are the odds? A: Order doesn't matter, use combination. 49C6 = 49!/(6!×43!) = 13,983,816 Odds of winning: 1 in 13,983,816 Example 4: Password Possibilities Q: How many 4-digit PINs using digits 0-9 without repetition? A: Order matters, use permutation. 10P4 = 10!/(10-4)! = 3,628,800/720 = 5,040 PINs
Key Properties
| Property | Formula | Explanation |
|---|---|---|
| Symmetry (Combinations) | nCr = nC(n-r) | Choosing r = leaving out (n-r) |
| Pascal's Identity | nCr = (n-1)C(r-1) + (n-1)Cr | Basis of Pascal's Triangle |
| Permutation-Relation | nPr = nCr × r! | Permutation = Combination × arrange r |
| Sum of Combinations | Σ(nCk) = 2ⁿ | Total subsets of n elements |
| Zero case | nC0 = 1, nP0 = 1 | One way to choose nothing |
| Same case | nCn = 1, nPn = n! | One way to choose all; n! to arrange |
Common Probability Applications
- Poker hands: 5-card hands from 52 cards = 52C5 = 2,598,960 possible hands
- Committee formation: Select 5 from 12 people = 12C5 = 792 ways
- Menu planning: Choose 3 appetizers from 8 = 8C3 = 56 combinations
- Route planning: Visit 4 cities in order from 10 = 10P4 = 5,040 routes
- Exam questions: Answer 5 from 8 questions = 8C5 = 56 ways to choose
Frequently Asked Questions
- What is the difference between permutation and combination?
- Permutation (nPr) counts arrangements where ORDER matters (e.g., passwords, race rankings, seating arrangements). Combination (nCr) counts selections where ORDER does NOT matter (e.g., lottery numbers, committee selection, pizza toppings). The key difference: permutations count different orderings as distinct, combinations treat them as the same.
- What is the formula for permutation?
- Permutation formula: nPr = n! / (n-r)! where n is total items and r is items selected. For example, 5P3 = 5!/(5-3)! = 120/2 = 60. This counts ways to arrange 3 items from 5 where order matters.
- What is the formula for combination?
- Combination formula: nCr = n! / (r! × (n-r)!) where n is total items and r is items selected. For example, 5C3 = 5!/(3!×2!) = 120/(6×2) = 10. This counts ways to select 3 items from 5 where order doesn't matter.
- When should I use factorial?
- Factorial (n!) is used when: arranging all n items (n! ways), calculating permutations (nPr uses factorials), calculating combinations (nCr uses factorials), or solving probability problems. Factorial grows very fast: 10! = 3,628,800, so calculators are useful for large n.
- What is 0! (zero factorial)?
- By mathematical convention, 0! = 1. This definition ensures formulas work correctly: nCn = n!/(n!×0!) = 1 (there's exactly one way to select all n items), and it maintains consistency in permutation/combination formulas.
- How do I know when order matters?
- Order matters (use permutation) when: positions/rankings differ (1st, 2nd, 3rd), arrangement creates different outcomes (ABC ≠ BAC), or sequence is important (passwords, codes). Order doesn't matter (use combination) when: selecting a group, all positions equivalent, or outcome is same regardless of sequence.