Built and fact-checked by the DocNectar team — see our editorial standards
Key Features
Instant Calculation
Get accurate results in real time with our optimized algorithm.
Mobile Friendly
Fully responsive design. Works on all devices & screen sizes.
Privacy Focused
Your data stays on your device. We don't store any inputs.
100% Free
No hidden costs. This tool is completely free forever.
A derangement is a permutation where absolutely no item ends up in its original position — the classic example being the "hat-check problem," where nobody gets their own hat back. This calculator finds the number of derangements of n items using the standard recurrence relation, with a full step-by-step solution.
How it works
Enter the number of items, n. The calculator applies the derangement recurrence !n = (n-1)(!(n-1) + !(n-2)), starting from the base cases !0 = 1 and !1 = 0, building up to n.
- Enter number of items (n).
- Click Calculate to see your results.
Examples
Derangements of 4 items
For n = 4, there are 9 derangements out of 24 total permutations — a probability of 37.5% that a random shuffle deranges every item.
Who should use it
- Solving combinatorics and probability problems involving the hat-check problem or similar "no fixed points" scenarios.
- Teaching or learning recurrence relations in a discrete math course.
Industry applications
- Combinatorics and discrete mathematics education
- Probability theory and statistics
Advantages
- Uses the exact recurrence relation rather than an approximation, giving an exact integer result.
- Reports the probability of a random permutation being a derangement alongside the count.
Limitations
- Grows extremely fast — results for larger n become very large integers quickly.
Common mistakes to avoid
- Confusing derangements with all permutations — a derangement specifically requires that no item remains in its original position.
- Using the wrong base cases in the recurrence, which throws off every subsequent value.
Best practices
- For quick approximate estimates at larger n, remember that !n / n! converges to about 1/e, without needing the full recurrence.
Tips
- The derangement probability !n/n! stabilizes near 36.8% for n as small as 6 or 7, so it's a useful mental shortcut for moderate-sized problems.