Try an Example
Pick a scenario to see how the calculator works, then adjust the values
Lottery Draw
Calculate the number of possible 6/49 lottery combinations.
Key values: Total balls: 49 · Drawn: 6 · Combination mode
Race Podium
Find the number of ways to award Gold, Silver, and Bronze among 8 runners.
Key values: Runners: 8 · Medals: 3 · Permutation mode
Secret Santa
Calculate valid gift assignments where nobody draws their own name.
Key values: Participants: 8 · Derangement mode
Password Keyspace
Estimate the number of possible 8-character passwords from printable ASCII.
Key values: Character set: 94 · Length: 8 · Repetition allowed
About This Calculator
Combinatorics is the branch of mathematics concerned with counting, arranging, and selecting objects. The two fundamental questions are: how many ways can you choose items from a set, and does the order matter? This calculator answers both, covering seven distinct counting operations in a single tool.
Supported operations include permutations (ordered arrangements), combinations (unordered selections), their with-repetition variants, factorials, derangements (permutations where no item is in its original position), and Catalan numbers (which count balanced parenthesizations, polygon triangulations, and other recursive structures).
The calculator uses BigInt arithmetic for exact results when (where standard IEEE 754 floating-point overflows), supports values of up to 10,000, and provides a Stirling approximation alongside the exact result for large inputs. An interactive Pascal's triangle lets you click any cell to compute instantly, and the step-by-step panel shows every stage of the formula evaluation.
How to Use
- Select an operation from the visual radio cards: Permutation, Combination, Perm + Rep, Stars & Bars, Factorial, Derangement, or Catalan.
- Enter n — the total number of distinct items in your set (0 to 10,000).
- Enter r — the number of items selected or arranged. This field is hidden for factorial, derangement, and Catalan modes (which depend only on ).
- Click Calculate to see the exact result, a step-by-step formula breakdown, and (where applicable) a P vs. C comparison panel, distribution bar chart, derangement convergence chart, or interactive Pascal's triangle.
- Click cells in Pascal's triangle (shown for combinations with ) to instantly set and and recalculate.
Formulas
Factorial
The factorial of is the product of all positive integers up to , with the convention that :
Factorials grow extremely fast — , and is the largest factorial representable in standard floating-point. Beyond that, this calculator uses BigInt for exact computation.
Permutations (Without Repetition)
The number of ways to arrange items from distinct items, where order matters:
When , by convention — you cannot arrange more items than exist in the set.
Permutations (With Repetition)
When order matters and each item can be reused (e.g., PIN codes, passwords):
Combinations (Without Repetition) — Binomial Coefficient
The number of ways to choose items from items, where order does not matter:
Key identity: — choosing items to include is identical to choosing items to exclude.
Combinations (With Repetition) — Stars and Bars
When order does not matter but items can be repeated (e.g., distributing identical objects into distinct bins):
This counts the number of non-negative integer solutions to .
Derangements (Subfactorial)
A derangement is a permutation where no element remains in its original position. The count is given by:
Equivalently, using the recurrence: with base cases and . Asymptotically, .
Catalan Numbers
The -th Catalan number counts balanced parenthesizations, polygon triangulations, non-crossing partitions, and valid push/pop sequences on a stack:
First values: 1, 1, 2, 5, 14, 42, 132, 429, 1430, ...
Pascal's Rule
Each entry in Pascal's triangle is the sum of the two entries directly above it:
Stirling's Approximation
For large , the factorial can be approximated logarithmically:
This calculator shows the Stirling approximation alongside the exact BigInt result for , letting you compare the two.
Relationship Between P and C
Permutations and combinations are related by:
In other words, the permutation count is always exactly times the combination count. The calculator's P vs. C comparison panel shows this ratio explicitly.
Worked Examples
Example 1: Lottery Draw (6/49)
A standard 6/49 lottery draws 6 balls from 49 numbered balls. Order does not matter and no ball can be drawn twice, so we use combinations.
- Set , , operation = Combination.
- Apply the formula: .
- Expand using the efficient form: .
There are 13,983,816 possible lottery tickets. The probability of winning the jackpot is — about 1 in 14 million.
Example 2: Committee with Roles
A club with 20 members elects a president, vice-president, and treasurer. Since each role is distinct, order matters — use permutations.
- Set , , operation = Permutation.
- Compute: .
Compare: if all three were equal committee members (no roles), . The ratio is , confirming .
Example 3: Secret Santa Derangements
Eight coworkers do a Secret Santa gift exchange. Each person draws a name at random. A valid assignment requires that nobody draws their own name — this is a derangement.
- Set , operation = Derangement.
- Using the recurrence with , :
Out of total arrangements, 14,833 are valid Secret Santa assignments. The probability that a random shuffle works is , which is already close to the asymptotic limit of .
Example 4: Ice Cream Scoops with Repetition
An ice cream shop offers 10 flavors. A customer wants 3 scoops in a bowl (order of scoops does not matter, repeats are allowed). Use combinations with repetition.
- Set , , operation = Stars & Bars.
- Apply the formula: .
- Compute: .
There are 220 different possible bowls of ice cream.
Example 5: DNA Codon Counting
DNA codons are sequences of 3 nucleotides from the alphabet {} — order matters and repetition is allowed.
- Set , , operation = Perm + Rep.
- Compute: .
64 possible codons exist — 61 encode amino acids and 3 are stop codons, consistent with the standard genetic code.
Example 6: Password Keyspace
How many 8-character passwords can be formed from 94 printable ASCII characters? Order matters and characters can be repeated.
- Set , , operation = Perm + Rep.
- Compute: .
Approximately 6 quadrillion possible passwords. At 1 billion guesses per second, brute-forcing this keyspace would take about 70 days.
Which Operation Should I Use?
The choice of formula depends on two questions: Does order matter? Can items repeat?
| Order matters? | Repetition? | Formula | Example |
|---|---|---|---|
| Yes | No | Podium finishes in a race | |
| Yes | Yes | PIN codes, passwords | |
| No | No | Lottery draws, committees | |
| No | Yes | Ice cream scoops, distributing identical objects |
Rule of thumb: If rearranging the selection gives a different outcome, use permutations. If rearranging gives the same outcome, use combinations.
Common Misconceptions
| Misconception | Why It Is Wrong |
|---|---|
| A "combination lock" uses combinations | A combination lock is actually a permutation lock — the sequence 1-2-9 is different from 9-2-1. Order matters, so permutations apply. |
| and give unrelated values | They are directly related: . Permutations count every ordering of each combination. |
| is undefined when | By convention, when — there are zero ways to choose more items than exist in the set. The formula evaluates cleanly. |
| Repetition always makes the count larger | True for combinations with repetition vs. without, but vs. can go either way depending on the relative sizes of and . |
| "When order matters" is always obvious | Context determines this. A committee of {Alice, Bob} is the same regardless of listing order (combination), but president=Alice, VP=Bob is different from president=Bob, VP=Alice (permutation). |
| Derangements are rare for large | The ratio converges rapidly to . For , roughly one-third of all permutations are derangements. |
Historical Context
The study of counting arrangements has deep roots across multiple cultures. Pascal's triangle — the single most important structure in elementary combinatorics — was independently discovered centuries before Blaise Pascal formalized it.
- India (c. 200 BC): The Sanskrit scholar Pingala described binary patterns in poetic meter in his Chandahsastra, producing what we now recognize as binomial coefficients. Commentary by Halayudha (c. 10th century AD) explicitly constructed the triangle.
- China (1261-1303 AD): Yang Hui described the triangle in 1261. Chu Shi-Chieh included it in his 1303 book Precious Mirror of the Four Elements, noting it was already known for over 300 years.
- Persia (11th century): Al-Karaji and Omar Khayyam independently worked with binomial coefficients in algebraic and geometric contexts.
- Europe (17th century): Blaise Pascal systematized the triangle's properties in his 1654 Traite du Triangle Arithmetique. His correspondence with Fermat on the "Problem of Points" launched mathematical probability theory, with combinations as a central tool.
The subfactorial (derangement count) was first studied by Pierre Remond de Montmort in 1708 and later by Leonhard Euler. The "hat-check problem" — in which guests check their hats and each receives a random hat back — became the canonical illustration. Catalan numbers were named after Eugene Charles Catalan (1838), though Euler had already counted polygon triangulations in the 18th century.
Pascal's Triangle
Pascal's triangle is a triangular array where row , position holds . It encodes row sums (), palindromic symmetry, diagonal sequences (naturals, triangulars), and binomial expansion coefficients.
For a deep dive into construction, key patterns (hockey stick identity, diagonals), the binomial theorem connection, and applications in probability and number theory, see the Pascal's Triangle Generator guide.
Connections to Other Fields
- Probability: The binomial distribution uses directly: .
- Computer science: Combinations appear in analyzing algorithms (subset enumeration, hash collisions), and the number of edges in a complete graph is .
- Cryptography: Permutation counting underlies keyspace size calculations and birthday attack analysis.
- Generating functions: The ordinary generating function for the -th row of Pascal's triangle is , linking it directly to the binomial theorem.
Frequently Asked Questions
What is the difference between a permutation and a combination?
A permutation counts arrangements where order matters (e.g., {} and {} are different). A combination counts selections where order does not matter (e.g., {} and {} are the same). They are related by .
When should I use combinations with repetition (Stars and Bars)?
Use this when you are distributing identical items into distinct categories, or when you can select the same item more than once and order does not matter. Classic examples include choosing ice cream scoops (repeats allowed), distributing identical coins among people, or counting non-negative integer solutions to an equation like .
What is a derangement?
A derangement is a permutation in which no element appears in its original position. The classic "hat-check problem" asks: if people check their hats and each receives a random hat back, how many arrangements leave nobody with their own hat? The surprising result is that this probability converges to very quickly — for , it is already within 0.3% of the limit.
What are Catalan numbers used for?
Catalan numbers appear in dozens of counting problems: the number of ways to correctly match pairs of parentheses, the number of triangulations of a polygon with sides, the number of valid sequences of push/pop operations on a stack, and the number of full binary trees with leaves.
How does the calculator handle very large numbers?
For , the calculator uses standard floating-point arithmetic. For , it switches to JavaScript's BigInt for exact computation. Results are displayed with commas for readability, along with the digit count and a Stirling's approximation for reference. values up to 10,000 are supported.
Why does the Pascal's triangle visualization cap at row 30?
Beyond row 30, the numbers grow too large and the cells too small to display meaningfully in an interactive grid. The calculator still computes exactly for any — the visual cap is purely a usability decision.
Is this calculator free?
Yes, completely free with no sign-up required. All seven operations, step-by-step solutions, the interactive Pascal's triangle, and all visualizations are available without restriction.
References
- Rosen, Kenneth H. Discrete Mathematics and Its Applications, 8th ed. McGraw-Hill, 2019. Chapters 6 and 8.
- NIST Digital Library of Mathematical Functions, Sections 5.9 and 26.1-26.4. https://dlmf.nist.gov/
- Weisstein, Eric W. “Permutation,” “Subfactorial,” “Catalan Number.” MathWorld — A Wolfram Web Resource. https://mathworld.wolfram.com/
- Flajolet, Philippe and Robert Sedgewick. Analytic Combinatorics. Cambridge University Press, 2009.
- Wikipedia. “Pascal's triangle,” “Derangement,” “Catalan number.” https://en.wikipedia.org/
Disclaimer
This calculator is provided for educational and informational purposes only. While the underlying algorithms produce exact results using BigInt arithmetic for inputs up to , very large computations may take a moment to process in-browser. The Stirling approximation is supplementary and may differ from the exact result in lower-order digits. Always verify critical calculations — particularly for cryptographic keyspace estimation, statistical modeling, or academic submissions — through independent means.
Specialized Calculators
Choose from 6 specialized versions of this calculator, each optimized for specific use cases and calculation methods.
Operation
6 CalculatorsRelated Calculators
6 CalculatorsMore Math calculators