More games at WuGames.ioSponsoredDiscover free browser games — play instantly, no download, no sign-up.Play

Combinatorics Calculator

Combinatorics calculator: permutations & combinations with or without repetition, factorials, n^r, stars and bars, BigInt steps.

On: permutation uses n^r and combination uses stars and bars C(n+r-1, r). Repetition allows r to exceed n.

Calculate permutations, combinations, and factorials with arbitrary-precision arithmetic that handles values up to thousands of digits without overflow.

What is Combinatorics?

Combinatorics is the branch of mathematics that counts arrangements and selections of finite collections. The three building blocks — factorial, permutation, and combination — together answer almost every "how many ways...?" question, from poker hand counts and lottery odds to algorithm running times and the structure of genetic codes. Each is computed from the others via short factorial expressions, so a single calculator covers the whole field.

Permutation (nPr)

A permutation is an arrangement where order matters. The number of ordered ways to pick r items from n distinct items is nPr = n! / (n − r)!. Equivalently, you have n choices for the first slot, n−1 for the second, ..., n−r+1 for the r-th — a product of r decreasing integers starting at n.

nPr = n! / (n - r)!

Example: arranging 3 letters chosen from {A, B, C, D} gives 4P3 = 4!/1! = 24 ordered triples (ABC, ABD, ACB, ACD, ...). A common real-world example: how many ways can 5 horses finish in the first 3 places of a race? Answer: 5P3 = 60.

Combination (nCr)

A combination is a selection where order does not matter. The number of ways to choose r items from n is nCr = n! / (r! × (n − r)!). It is also written C(n,r) or "n choose r" and equals nPr divided by r! — the r! removes the orderings among the chosen items.

nCr = n! / (r! × (n - r)!)

Example: choosing 3 letters from {A, B, C, D} gives 4C3 = 4 selections ({A,B,C}, {A,B,D}, {A,C,D}, {B,C,D}). Real-world: a lottery picking 6 numbers from 49 has 49C6 = 13,983,816 possible tickets, so the chance of winning the jackpot with one ticket is roughly 1 in 14 million.

Factorial (n!)

The factorial of n is the product of all positive integers up to n: n! = 1 × 2 × 3 × ... × n, with the convention 0! = 1 (the empty product). It counts the number of orderings of n distinct items and appears as the building block of both nPr and nCr.

n! = n × (n - 1) × (n - 2) × ... × 2 × 1

Factorials grow faster than any polynomial or simple exponential. 10! = 3,628,800, 20! = 2,432,902,008,176,640,000, and 70! ≈ 1.2 × 10¹⁰⁰. Beyond 170!, IEEE-754 doubles overflow — this calculator uses BigInt so the exact value is preserved for any input you can wait for.

Applications of Combinatorics

Combinatorics has wide applications across many fields:

  • Probability & Statistics: poker hand counts, birthday paradox, sampling without replacement
  • Computer Science: counting paths, algorithm complexity, hash collision probability, error-correcting codes
  • Cryptography: key-space size estimation, password strength, brute-force feasibility
  • Game Theory: counting game states, perfect-play analysis, evaluating decision trees
  • Biology and Chemistry: genetic combinations, molecular isomers, RNA secondary structures
  • Operations Research: scheduling, routing, bin packing, tournament brackets

Frequently Asked Questions

The single rule: does the order matter? If yes, use a permutation. If no, use a combination. A permutation counts arrangements: positions 1st/2nd/3rd in a race, the first three letters of a password, the order of speeches at a conference. A combination counts selections: which 5 cards are in your poker hand, which 3 people are on a committee, which 6 numbers win the lottery. The relationship is nPr = nCr × r! — every combination of r items has r! orderings, and the permutation counts all of them. Example: choosing 2 letters from {A,B,C,D}. Combinations: {A,B}, {A,C}, {A,D}, {B,C}, {B,D}, {C,D} = 6. Permutations: also AB and BA, AC and CA, ... so 12. nP2 = 4!/2! = 12; nC2 = 4!/(2!·2!) = 6. Note 12 = 6 × 2! = 6 × 2. When in doubt, write out a small example by hand to check whether AB and BA count as the same or different in your problem.

Because choosing which r items to include is mathematically identical to choosing which n−r items to leave out. Every selection of r items uniquely specifies a complementary set of n−r leftovers, and vice versa, so the two counts must be equal. For 10 people choosing a 3-person committee, C(10,3) = 120. Equivalently, you are choosing the 7 people who are not on the committee, and C(10,7) = 120 — same number. This symmetry is also visible in the formula: C(n,r) = n!/(r!(n−r)!) is unchanged by swapping r and n−r. The practical implication is computational: to compute C(100, 97), do not loop 97 times — compute C(100, 3) instead, which is the same value and takes 3 multiplications. Pascal's triangle exhibits this symmetry as the left-right mirror of each row, and the binomial theorem (a+b)^n = Σ C(n,k) a^(n−k) b^k uses the symmetry to express any expansion in the smaller of the two equivalent forms.

Pascal's triangle is the array of binomial coefficients arranged so that each row n contains C(n,0), C(n,1), ..., C(n,n). Row 0 is just 1; row 1 is 1 1; row 2 is 1 2 1; row 3 is 1 3 3 1; and so on. The pattern is generated by the recurrence C(n,k) = C(n−1, k−1) + C(n−1, k) — each interior entry is the sum of the two above it. Combinatorial reasoning: to pick k items from n, either the n-th item is included (then pick k−1 from the remaining n−1) or excluded (then pick k from the remaining n−1). The triangle was studied independently in many cultures — China (Yang Hui, 1261), Persia (Al-Karaji, c. 1000), India (Halayudha's commentary on Pingala, c. 950), and France (Blaise Pascal, 1654) — and shows up everywhere from the binomial theorem to fractals (Sierpinski's triangle is Pascal's mod 2) to the Catalan numbers and Fibonacci sequence (sums of shallow diagonals).

Repetition turns the formulas inside out. With repetition allowed, the number of ordered arrangements of r items from n choices is n^r — for each of the r slots, you independently pick any of the n items. Example: a 4-digit PIN over 10 digits = 10^4 = 10,000. The number of unordered selections with repetition ("multisets") is C(n + r − 1, r) — this is the "stars and bars" formula. Example: distributing 5 identical candies among 3 children is C(5+3−1, 5) = C(7,5) = 21. Without repetition, the standard nPr and nCr apply. Quick decision matrix: order matters + repetition → n^r; order matters + no repetition → nPr; order doesn't matter + no repetition → nCr; order doesn't matter + repetition → C(n+r−1, r). Mismatching these four cases is the most common source of probability errors on exams and in coding interviews.

In a room of just 23 people, the probability that at least two share a birthday exceeds 50%; with 70 people it exceeds 99.9%. This shocks most people because intuition expects 365/2 ≈ 180 people would be needed. The trick is that we are not asking "does anyone share my birthday" (which would need ~180 people) but "does any pair among the room share" — and the number of pairs grows quadratically as C(n,2). With 23 people there are 253 pairs, each with a ~1/365 chance of matching, giving roughly 253/365 ≈ 69% — close to the exact value. The exact calculation works with the complement: P(all distinct) = 365/365 × 364/365 × 363/365 × ... × (365−n+1)/365, and P(at least one match) = 1 − P(all distinct). This same combinatorial structure is why hash collisions appear after roughly √N hashes on N-bit hashes (an attack called the birthday attack in cryptography), and why MD5 (128-bit) is no longer considered collision-resistant at 2^64 ≈ 18 quintillion samples.

Most lotteries pick a small set of numbers from a larger pool. The odds of getting all of them is 1 over the number of possible draws, which is a combination because order does not matter. Lotto 6/49 (Canada, Spain): C(49,6) = 13,983,816 — about 1 in 14 million. Powerball (USA): pick 5 from 69 white balls and 1 from 26 red, so C(69,5) × 26 = 11,238,513 × 26 = 292,201,338 — about 1 in 292 million. EuroMillions: C(50,5) × C(12,2) = 139,838,160. The chance of winning any prize is much better because most lotteries pay smaller prizes for partial matches (e.g., 3 numbers out of 6). For Lotto 6/49, the chance of getting exactly 3 of 6 numbers is C(6,3) × C(43,3) / C(49,6) ≈ 1 in 57. The reason house edges are so large is not the headline jackpot odds, but the prize pool: typical lotteries return only 50–60% of revenue as prizes, with the rest going to operations, taxes, and good-cause funds.

C(n, 0) is 1 because there is exactly one way to choose nothing — the empty selection. This makes intuitive sense and is also forced by the formula: C(n, 0) = n! / (0! × n!) = 1, where 0! = 1 by convention. C(n, n) is 1 because there is exactly one way to choose everything — the full set. The formula gives C(n, n) = n! / (n! × 0!) = 1. These edge cases matter for the binomial theorem: (1 + x)^n = Σ C(n, k) x^k includes both a constant term (k = 0, coefficient C(n,0) = 1) and a top term (k = n, coefficient C(n,n) = 1). They also match the symmetry C(n, k) = C(n, n−k) — choosing 0 to include is the same as choosing all n to exclude. Both endpoints of every row of Pascal's triangle are 1, and the row sums equal 2^n because that is the total number of subsets of an n-element set.

This calculator uses BigInt for arbitrary precision, so there is no fixed limit — only practical ones. The bottleneck is multiplying very large integers, which BigInt does in roughly O((digits)^1.58) time with the Karatsuba algorithm. For factorials: 100! has 158 digits and computes in milliseconds; 1000! has 2568 digits and takes a fraction of a second; 100000! has 456,574 digits and takes several seconds; 1,000,000! has 5,565,709 digits and may take a minute or two and several hundred MB of memory. For combinations and permutations, the result is usually much smaller than n! because of the cancellations in the formula, so C(1000, 5) = 8.25 × 10¹² is instant even though 1000! is huge. For statistical purposes, Stirling's approximation log(n!) ≈ n ln(n) − n + 0.5 ln(2πn) gives the log of any factorial in O(1) — useful for entropy calculations, log-likelihoods, and informational metrics where you do not need every digit.
Combinatorics Calculator — Combinatorics calculator: permutations & combinations with or without repetition, factorials, n^r, stars and bars, BigIn
Combinatorics Calculator