Derangement Calculator
Count derangements !n, where no item stays in its place, with the Secret Santa probability and the distribution of fixed points.
A derangement is a reordering in which no item ends up in its original position: the classic hat-check problem, or a Secret Santa draw where nobody picks their own name. This calculator gives the number of derangements !n, the chance that a random shuffle is a derangement, and the full distribution of how many items stay in place.
How to use this tool
- Enter the number of items: people, letters, hats or seats.
- Leave “items left in place” at 0 for derangements, or enter k to count arrangements with exactly k items where they started.
- Read the count and its probability; the table shows every possible number of fixed points.
Formula
!n = n! × Σ (−1)ᵏ / k! for k = 0 … n !n = (n − 1) × (!(n − 1) + !(n − 2)), with !0 = 1 and !1 = 0
The first formula comes from inclusion–exclusion over the items that stay put. For n ≥ 1, !n also equals n!/e rounded to the nearest whole number. Arrangements with exactly k fixed points (rencontres numbers) are C(n, k) × !(n − k): choose which k stay, then derange the rest.
Example
4 people swap gifts: there are 4! = 24 ways to hand them out, and !4 = 3 × (!3 + !2) = 3 × (2 + 1) = 9 in which nobody gets their own, so the chance is 9/24 = 37.5%. Exactly one person gets their own gift in C(4, 1) × !3 = 4 × 2 = 8 ways. For 8 people, !8 = 14,833 of 40,320 orders, about 36.79%.
Frequently asked questions
What is the chance nobody draws their own name in Secret Santa?
About 36.7–36.8% for any group of five or more, because !n / n! approaches 1/e ≈ 0.3679 very quickly. In roughly two draws out of three at least one person picks themselves and the hat has to be redrawn.
What is !0?
By convention !0 = 1: there is exactly one way to arrange nothing, and it leaves nothing in place. This keeps the recurrence and the rencontres formula consistent.
How is a derangement different from a permutation?
A permutation is any ordering, and there are n! of them. A derangement is a permutation with no fixed points, so there are always fewer, roughly 37% of all permutations.
Is a derangement number the same as a subfactorial?
Yes. !n is called the subfactorial of n, and the two names are used interchangeably.
Last updated: 2026-10-30