Derangements Calculator
- A derangement is a permutation in which no element stays in place. Count them with the recurrence !(n) = (n - 1) x (!(n - 1) + !(n - 2)), starting from !0 = 1 and !1 = 0.
- For n = 5 that recurrence gives 44 derangements out of 120 permutations in total.
- The chance that a random shuffle moves every element is 44 / 120 = 36.67% - it settles near 1/e, about 36.79%, as n grows.
A derangements calculator counts the permutations in which no element stays in place. For five elements, there are 44 derangements out of 120 permutations, a 36.67% chance. For eight elements, the count is 14,833 derangements out of 40,320 permutations, or 36.79%. For ten elements, it is 1,334,961 derangements out of 3,628,800, still 36.79%. Enter the number of elements and the calculator gives you the derangement count, the total number of permutations, and the probability that a random shuffle leaves nothing in place.
The count comes from the recurrence !(n) = (n - 1) x (!(n - 1) + !(n - 2)), starting from !0 = 1 and !1 = 0. That recurrence is the standard way to compute subfactorials, so the results match the accepted derangement counts. The probability ratio converges fast: as n grows, the chance a random shuffle deranges settles near 1/e, about 36.79%. This page shows the formula, step-by-step workings, worked examples and sources so you can check every number yourself.
Worked examples
Five elements
Five elements have 44 derangements out of 120 permutations - a 36.67% chance. (5)
| Number of derangements | 44 |
| Total permutations | 120 |
| Chance a shuffle deranges | 36.67% |
Eight elements
Eight elements have 14,833 derangements out of 40,320 - 36.79%. (8)
| Number of derangements | 14,833 |
| Total permutations | 40,320 |
| Chance a shuffle deranges | 36.79% |
Ten elements
Ten elements have 1,334,961 derangements out of 3,628,800 - still 36.79%. (10)
| Number of derangements | 1,334,961 |
| Total permutations | 3,628,800 |
| Chance a shuffle deranges | 36.79% |
What a derangement is
A derangement is a permutation in which no element stays in place. If you shuffle a list, a derangement is a shuffle where every single item ends up somewhere other than where it started. That one condition turns an ordinary counting question into a surprisingly interesting one, and a derangements calculator is simply a tool for counting these arrangements without listing them all by hand.
The classic framing is the hat-check problem. A group of people hands their hats to a clerk, and the clerk hands the hats back at random. A derangement is the outcome where nobody gets their own hat back. The same question appears under other names: the secret-Santa problem, where no person may draw their own name, and the letter-envelope problem, where letters are stuffed into envelopes so that no letter lands in its own envelope. Different stories, identical math. Once you strip away the hats, names, and envelopes, each one asks how many ways you can rearrange n items so that not a single item remains fixed.
Small cases make the idea concrete. With five elements there are 120 possible permutations, and 44 of them are derangements, so a random shuffle lands on a derangement 36.67% of the time. The count grows quickly. Eight elements have 14,833 derangements out of 40,320 permutations, or 36.79%. Ten elements have 1,334,961 derangements out of 3,628,800, and the share is still 36.79%. Notice that the percentage barely moves even as the numbers explode.
You do not need to enumerate permutations to get these counts. The recurrence !(n) = (n - 1) x (!(n - 1) + !(n - 2)) builds each value from the two before it, starting from !0 = 1 and !1 = 0. That is exactly the kind of arithmetic a derangements calculator handles instantly, and it explains why the totals above can be produced for large n without writing out every arrangement.
There is a reason the percentage holds so steady. As n grows, the chance that a random shuffle deranges everything settles near 1/e, about 36.79%. The subfactorial ratio converges fast, so even modest values of n are already close to the long-run figure. That convergence is why the five-element case at 36.67% and the ten-element case at 36.79% look so similar: the sequence has essentially locked in on its limit very early.
The recurrence
The derangements calculator doesn't have to check every permutation one by one. It can build each count from the two that came before, using the recurrence !(n) = (n - 1) x (!(n - 1) + !(n - 2)). Start with !0 = 1 and !1 = 0, and every later value follows from those two seeds. The rest of this section explains where that formula comes from, because the reasoning is easier to trust than the result alone.
Take the first element of an n-element set. In a derangement it cannot stay where it is, so it must go to one of the other n - 1 positions. That gives the (n - 1) factor out front. Now fix one such destination and look at what happens to the element that normally lives there. There are exactly two cases, and they are the two terms inside the parentheses.
In the first case, the two elements swap: the first element moves into the other's spot, and the other moves into the first's spot. Both are now settled and neither is in place, so the remaining n - 2 elements must form a derangement among themselves. That contributes !(n - 2). In the second case, the two elements do not simply swap. The first element takes the other's spot, but the other element must still avoid its own original position, which is now occupied. Treat that displaced element as if its forbidden spot were the first element's original position, and the remaining n - 1 elements must form a derangement. That contributes !(n - 1). Add the two cases and multiply by the n - 1 possible destinations, and you have the recurrence.
The numbers grow quickly but stay believable. Five elements have 44 derangements out of 120 permutations, a 36.67% chance. Eight elements have 14,833 derangements out of 40,320 permutations, or 36.79%. Ten elements have 1,334,961 derangements out of 3,628,800, still 36.79%. Notice how little the percentage moves once n is large enough to matter.
That stability is the point. As n grows, the chance that a random shuffle deranges settles near 1/e, about 36.79%, and the subfactorial ratio converges fast. So the recurrence is not just a counting shortcut; it shows why the answer to "what are the odds nothing stays put?" barely changes as the set gets bigger.
Worked examples
The recurrence !(n) = (n - 1) x (!(n - 1) + !(n - 2)) builds every derangement count from just two starting values: !0 = 1 and !1 = 0. Walking a few values by hand shows how quickly the numbers grow and how stable the resulting probability becomes. A derangements calculator runs this same recurrence for whatever n you enter, but working through n = 5, 8 and 10 yourself makes the pattern visible.
For n = 5, you need !4 and !3. Starting from !0 = 1 and !1 = 0: !2 = (2 - 1) x (!1 + !0) = 1 x (0 + 1) = 1; !3 = (3 - 1) x (!2 + !1) = 2 x (1 + 0) = 2; !4 = (4 - 1) x (!3 + !2) = 3 x (2 + 1) = 9. Then !5 = (5 - 1) x (!4 + !3) = 4 x (9 + 2) = 44. Five elements have 44 derangements out of 120 permutations - a 36.67% chance that a random shuffle leaves nothing in place.
For n = 8, continue the same chain: !6 = 5 x (44 + 9) = 265, !7 = 6 x (265 + 44) = 1,854, and !8 = 7 x (1,854 + 265) = 14,833. Eight elements have 14,833 derangements out of 40,320 permutations - 36.79%. Two more steps reach n = 10: !9 = 8 x (14,833 + 1,854) = 133,496, and !10 = 9 x (133,496 + 14,833) = 1,334,961. Ten elements have 1,334,961 derangements out of 3,628,800 - still 36.79%.
Notice how little the percentage moves across these examples: 36.67% at n = 5, then 36.79% at both n = 8 and n = 10. As n grows the chance a random shuffle deranges settles near 1/e, about 36.79% - the subfactorial ratio converges fast. That means even for small collections, the derangement probability is already close to its long-run value, and the counts themselves are what explode as n increases.
- n = 5: !5 = 4 x (9 + 2) = 44 derangements out of 120 permutations - 36.67%
- n = 8: !8 = 7 x (1,854 + 265) = 14,833 out of 40,320 permutations - 36.79%
- n = 10: !10 = 9 x (133,496 + 14,833) = 1,334,961 out of 3,628,800 - 36.79%
The 1/e limit
The chance that a random shuffle of n items is a derangement is !n divided by n!. The surprising part is that this ratio barely moves once n gets past about ten. A derangements calculator will show the count itself growing enormously, but the percentage it represents settles down to almost the same value every time.
You can watch the ratio close in on its target with a few examples. Five elements have 44 derangements out of 120 permutations, a 36.67% chance. Eight elements have 14,833 derangements out of 40,320 permutations, which is 36.79%. Ten elements have 1,334,961 derangements out of 3,628,800, and that is still 36.79%. From eight elements to ten, the count of derangements jumps from five digits to seven, yet the probability stays put at the same two decimal places.
The destination of that sequence is 1/e, roughly 36.79%. As n grows, the chance a random shuffle deranges settles near 1/e, and the subfactorial ratio converges fast. The reason is that the proportion of permutations fixing no element can be written as an alternating sum of reciprocal factorials, and that sum is the series for 1/e. Each new term is smaller than the last by a factor of n, so the tail shrinks quickly and the running total stops changing in any visible way after only a handful of terms.
That is why the answer feels almost independent of n beyond about ten. If you use a derangements calculator to compare ten elements with twenty, the derangement counts will differ by many orders of magnitude, but the percentages will agree to several decimal places. The recurrence !(n) = (n - 1) x (!(n - 1) + !(n - 2)), starting from !0 = 1 and !1 = 0, is still the reliable way to get the exact count; the 1/e limit simply tells you what fraction of the n! permutations that count will turn out to be.
- 5 elements: 44 of 120 permutations, 36.67%
- 8 elements: 14,833 of 40,320 permutations, 36.79%
- 10 elements: 1,334,961 of 3,628,800 permutations, 36.79%
- Limit as n grows: about 1/e, roughly 36.79%
FAQs
What is a derangement?
A derangement is a permutation of a set in which no element appears in its original position. In other words, every item ends up somewhere other than where it started. For a set of 5 elements, there are 44 such permutations. The derangements calculator counts these arrangements for any size you enter.
How do you count derangements?
You count derangements with the recurrence !(n) = (n - 1) x (!(n - 1) + !(n - 2)), starting from the base values !0 = 1 and !1 = 0. Each new count builds on the two before it, so the calculator can reach large n quickly without listing every permutation one by one.
What is the chance a random shuffle is a derangement?
About 36.79% for any sizeable n. The probability is the ratio !n / n!, and that ratio tends to 1/e as n grows. So no matter how large the set, a random shuffle has roughly the same chance of leaving no element in its original position.
What is the subfactorial?
The subfactorial is another name for the derangement count, written !n. It is the number of permutations of n elements with no fixed points, meaning no element stays in its original position. The derangements calculator computes this subfactorial value for the size you enter.
What is the hat-check problem?
In the hat-check problem, n people pick hats at random. The chance that nobody gets their own hat is !n / n!, which is about 36.79% for large n. It is a classic way to picture derangements: the hats are returned in some order, and you ask whether every person receives someone else's hat.
Why does the chance stay near 36.79%?
The inclusion-exclusion sum for derangements is the series for 1/e, so the ratio !n / n! converges to 1/e = 0.3679 as n grows. That is why the probability settles near 36.79% instead of shrinking toward zero, even as the set gets larger.