Study and Productivity

Beyond nCr: Derangements, Partitions and Other Counting Numbers

Learn the counting formulas beyond permutations and combinations: circular arrangements, repetition, multinomials, derangements, Stirling, Bell, Catalan.

Saizul Amin
Saizul Amin30 Oct 2026 · 3 min read
Beyond nCr: Derangements, Partitions and Other Counting Numbers

Beyond nCr: Derangements, Partitions and Other Counting Numbers

Counting sounds simple until the questions get interesting. How many ways can eight people sit around a table? How many ways can a secretary put every letter in the wrong envelope? How many ways can a number be split into a sum? Combinatorics has elegant answers, and this guide introduces the most useful ones. You can compute them exactly with the advanced combinatorics calculator.

Two questions decide the formula

  1. Does order matter?
  2. Is repetition allowed?
No repetitionRepetition allowed
Order mattersnPr = n!/(n − r)!n^r
Order does not matternCr = n!/(r!(n − r)!)C(n + r − 1, r)

Choosing 3 scoops from 10 ice-cream flavours, repeats allowed and order irrelevant, gives C(12, 3) = 220 possibilities.

Circular arrangements

Seating n people around a round table: rotations give the same arrangement, so there are (n − 1)! ways. Ten guests can sit in 362,880 ways. If the arrangement can also be flipped, like beads on a bracelet, divide by 2.

Multinomial coefficients

To split n items into groups of sizes k₁, k₂, …, kₘ:

n! / (k₁! k₂! … kₘ!).

The letters of MISSISSIPPI (1 M, 4 I, 4 S, 2 P) can be arranged in 34,650 distinct ways.

Derangements

A derangement is a permutation where nothing stays in its original place: letters in the wrong envelopes, hats returned to the wrong owners. The count !n satisfies !n = (n − 1)(!(n − 1) + !(n − 2)): 1, 2, 9, 44, 265… Remarkably, the probability that a random permutation is a derangement approaches 1/e ≈ 36.8 % as n grows.

Stirling numbers of the second kind

S(n, k) counts the ways to split n distinct objects into k non-empty groups. S(5, 2) = 15: fifteen ways to divide five people into two teams of any size.

Bell numbers

The Bell number B(n) counts all ways to split n objects into groups, of any number: 1, 1, 2, 5, 15, 52, 203… Five people can be grouped in 52 ways.

Integer partitions

p(n) counts the ways to write n as a sum of positive integers, ignoring order. 4 = 4 = 3 + 1 = 2 + 2 = 2 + 1 + 1 = 1 + 1 + 1 + 1, so p(4) = 5. The numbers grow quickly: p(10) = 42, p(100) = 190,569,292. Ramanujan and Hardy found an astonishing formula for their growth. The calculator uses Euler's pentagonal number recurrence for exact values.

Catalan numbers

C_n = C(2n, n) / (n + 1) counts many structures: correctly matched pairs of brackets, binary trees with n internal nodes, ways to triangulate a polygon with n + 2 sides. The sequence starts 1, 1, 2, 5, 14, 42.

Exactness matters

Counting numbers grow explosively: 20! exceeds 2 × 10¹⁸, beyond the exact range of ordinary floating-point numbers. The calculator uses big integers, so every answer is exact.

Using the calculator

  1. Enter n and r.
  2. Enter group sizes for a multinomial coefficient.
  3. Read all the counts.

The birthday problem

Counting also answers surprising probability questions. The chance that at least two of 23 people share a birthday is 1 − 365!/(342! × 365²³) ≈ 50.7 %. The numerator counts ordered selections without repetition, the denominator with repetition.

Inclusion-exclusion

Many counting problems, including derangements, are solved by the inclusion-exclusion principle: count everything, subtract the cases with one forbidden property, add back those with two, and so on.

Small cases are worth listing by hand to check a formula.

Limits

n is limited to 400 (Bell numbers to 200) to keep calculations fast. Very large results are shown in scientific notation.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages