Derangement Calculator

Derangements of 6 items265
Arrangements in total (6!)720
Share with no fixed points0.36806
Check: nearest integer to n!/e265
How this was calculated
  1. A derangement is a permutation in which no item stays in its own place - no fixed points at all. The count, written !6 and called the subfactorial, follows the recurrence !n = (n - 1) x (!(n - 1) + !(n - 2)): item 1 swaps into one of 5 other positions, and what follows is either a swap back or a smaller derangement.
  2. Running the recurrence from !0 = 1 and !1 = 0 up to n = 6 gives !6 = 265, out of 720 permutations in total.
  3. The share with no fixed points is 265 / 720 = 0.36806, already close to 1/e = 0.36788 - which is why !n is simply the nearest integer to n!/e, here 265.
  4. This is the hat-check problem: the probability that nobody at a party gets their own hat back barely changes once there are more than a handful of hats, settling at about 36.8 %.

A derangement is a permutation in which no item ends up back in its original position. This derangement calculator counts those arrangements for any set size you enter, so you can see how many orderings leave nothing in place. The counts grow fast: of the 24 permutations of 4 items, exactly 9 are derangements, a share of 0.37500. For 6 items, 265 of the 720 permutations leave nothing in place, a share of 0.36806. For 10 items there are 1,334,961 derangements out of 3,628,800 permutations, a share of 0.36788. That share converges to 1/e = 0.36788, which is why !n is the nearest integer to n!/e.

The method behind these results is the subfactorial recurrence, !n = (n - 1) x (!(n - 1) + !(n - 2)), starting from !0 = 1 and !1 = 0. This recurrence is the accepted standard for counting derangements because it builds each count directly from the two smaller cases, so the totals match the exact enumeration shown above. The same problem appears as the hat-check problem: the chance nobody gets their own hat back settles near 36.8 %. This page shows the formula, step-by-step workings, worked examples and sources, so you can follow each count rather than just read the final number.

Worked examples

Four items

(4)

Derangements of 4 items9
Arrangements in total (4!)24
Share with no fixed points0.37500
Check: nearest integer to n!/e9

Six items

(6)

Derangements of 6 items265
Arrangements in total (6!)720
Share with no fixed points0.36806
Check: nearest integer to n!/e265

Ten items

(10)

Derangements of 10 items1,334,961
Arrangements in total (10!)3,628,800
Share with no fixed points0.36788
Check: nearest integer to n!/e1,334,961

How derangements are counted

A derangement is a rearrangement of items in which nothing ends up back where it started. Counting them is easier than it first appears, because each derangement count can be built from the two counts before it. The subfactorial recurrence is !n = (n - 1) x (!(n - 1) + !(n - 2)), starting from !0 = 1 and !1 = 0. Those two starting values anchor the whole chain: with zero items there is one way to arrange nothing, and with one item there is no way to move it away from its own place.

The recurrence works by fixing one item and asking where it can go. It has n - 1 possible destinations, which is where the (n - 1) multiplier comes from. Once that item is placed, the remaining items fall into one of two cases, and those cases are exactly the previous two subfactorial counts, !(n - 1) and !(n - 2). Adding the two cases and multiplying by the n - 1 choices gives the next value.

Running the recurrence from the anchors produces the sequence step by step. !2 = (2 - 1) x (!1 + !0) = 1 x (0 + 1) = 1. !3 = 2 x (!2 + !1) = 2 x (1 + 0) = 2. !4 = 3 x (!3 + !2) = 3 x (2 + 1) = 9. !5 = 4 x (!4 + !3) = 4 x (9 + 2) = 44. !6 = 5 x (!5 + !4) = 5 x (44 + 9) = 5 x 53 = 265. So !6 = 265, matching the fact that for 6 items, 265 of the 720 permutations leave nothing in place, a share of 0.36806.

The same sequence can be checked against smaller and larger cases. Of the 24 permutations of 4 items, exactly 9 are derangements - a share of 0.37500, which is the !4 = 9 value the recurrence produced. For 10 items there are 1,334,961 derangements out of 3,628,800 permutations, a share of 0.36788. The share converges to 1/e = 0.36788, so !n is the nearest integer to n!/e. That gives a second, independent way to check any value a derangement calculator returns.

The problem has a familiar story attached. This is the hat-check problem: the chance nobody gets their own hat back settles near 36.8 %. The recurrence and the 1/e shortcut agree at every step, which is why the derangement calculator can report both an exact count and the share it represents.

Recurrence check: !4 = 9, !5 = 44, !6 = 5 x (44 + 9) = 265.

The hat-check problem

The hat-check problem is the classic way to see a derangement calculator at work. Picture a cloakroom attendant who hands back four hats in a random order. There are 24 possible orders in which the four hats can be returned, and exactly 9 of those orders give nobody their own hat. That is a share of 0.37500 — a little over a third of the time, everyone walks away with someone else's hat.

Add hats and the arithmetic gets heavier but the answer barely budges. With six hats, 265 of the 720 possible orders leave nothing in place, a share of 0.36806. With ten items, the counts grow quickly: 1,334,961 derangements out of 3,628,800 permutations, a share of 0.36788. The numbers of arrangements explode, yet the fraction that are derangements settles down instead of drifting away.

The reason is that the share converges to 1/e, which is 0.36788. Because of this, the number of derangements of n items, written !n, is the nearest integer to n!/e. So once you know how many ways the items can be arranged, dividing by e and rounding gives you the derangement count almost instantly. The recurrence !n = (n - 1) x (!(n - 1) + !(n - 2)) does the same job step by step, starting from !0 = 1 and !1 = 0.

The practical upshot is that after the first few cases, adding more hats changes the probability by less than a thousandth. Four hats give 0.37500, six give 0.36806, and ten give 0.36788 — the last two differ in the fourth decimal place. By the time you reach ten items, the chance nobody gets their own hat back is essentially fixed near 36.8 percent, no matter how long the queue at the cloakroom gets.

The chance nobody gets their own hat back settles near 36.8% — the same value the derangement share converges to, 1/e = 0.36788.

The 1/e limit

As the number of items grows, the share of permutations that are derangements settles into a remarkably stable pattern. You can watch it happen in the numbers: of the 24 permutations of 4 items, exactly 9 are derangements, a share of 0.37500. For 6 items, 265 of the 720 permutations leave nothing in place, a share of 0.36806. For 10 items there are 1,334,961 derangements out of 3,628,800 permutations, a share of 0.36788. Each step the share drifts a little closer to a fixed value, and that value is 1/e = 0.36788.

That convergence is what makes a derangement calculator so quick in practice. Because the share converges to 1/e = 0.36788, !n is the nearest integer to n!/e. Instead of building every permutation and checking whether anything stayed put, you can divide n! by e and round to the nearest whole number. The shortcut is exact at n = 10: n!/e gives a value that rounds to 1,334,961, the same count the long way confirms out of 3,628,800 permutations. Rounding to the nearest integer is the key step - the fractional part of n!/e is always close enough to the whole-number answer that rounding recovers the true count.

If you would rather count step by step than divide and round, the subfactorial recurrence does the job: !n = (n - 1) x (!(n - 1) + !(n - 2)), starting from !0 = 1 and !1 = 0. Each derangement count is built from the two before it, so the sequence grows without ever needing to list a single arrangement. The two methods agree, which is a useful check when you are working through a problem by hand.

This is the hat-check problem: the chance nobody gets their own hat back settles near 36.8 %. The same figure shows up whenever items are shuffled and you ask how likely it is that none lands where it started - letters and envelopes, names and Secret Santa slips, or any random reassignment with no fixed points. The share never drops to zero and never rises above that early 0.37500; it simply closes in on 1/e from one side.

The practical upshot is that the size of the set barely changes the answer once n is reasonably large. Whether you are checking 6 items at 0.36806 or 10 items at 0.36788, the share is already within a hair of the limit, and a derangement calculator can lean on the n!/e shortcut with confidence.

Watch the share converge: 0.37500 at 4 items, 0.36806 at 6 items, 0.36788 at 10 items - the last already equal to 1/e to five decimal places.

Derangements in practice

A derangement is a rearrangement in which nothing lands back where it started, and that idea shows up in more everyday situations than its formal name suggests. The classic case is the Secret Santa draw: names go into a hat, each person pulls one, and the organizer hopes nobody draws their own name. Run the numbers and the outcome is surprisingly consistent. With 4 people, 9 of the 24 possible permutations are derangements, a share of 0.37500. With 6 people, 265 of the 720 permutations leave nothing in place, a share of 0.36806. With 10 people, 1,334,961 of the 3,628,800 permutations are derangements, a share of 0.36788.

That last figure is not a coincidence. The share converges to 1/e = 0.36788, which means the count of derangements, written !n, is the nearest integer to n!/e. So whether you are arranging 4 gifts or 10, roughly 37 percent of random shuffles leave every person with someone else's name. A derangement calculator simply does the counting for you, returning the exact number rather than an estimate.

The same structure appears in the problem that gave derangements their original name, the probleme des rencontres. Picture letters being placed into addressed envelopes at random, or hats returned to their owners after a party. The question is how often every letter is misdelivered or every hat goes to the wrong person. This is the hat-check problem, and its answer follows the same curve: the chance nobody gets their own hat back settles near 36.8 percent. The early cases move around a little, but the value stabilizes quickly as the group grows.

If you want to compute these counts by hand, the subfactorial recurrence is !n = (n - 1) x (!(n - 1) + !(n - 2)), starting from !0 = 1 and !1 = 0. Each new term builds on the two before it, which is why the totals grow fast even while the share stays close to 1/e. The recurrence also explains why a random shuffle so often leaves something in place: most permutations are not derangements, and the ones that are cluster around that steady 36.8 percent share.

About 36.8 percent of random arrangements leave nothing in place, and that share holds steady as the number of items grows.

FAQs

What is a derangement?

A derangement is a permutation in which no item ends up in its original position — every element is displaced, so there are no fixed points. For example, of the 24 permutations of 4 items, 9 qualify as derangements. The rest leave at least one item in its starting spot, which disqualifies them.

How many derangements of 6 are there?

There are 265 derangements of 6 items, written !6 = 265. That is out of 720 total permutations of 6 items, so a little over a third of all arrangements of six items leave nothing in its original place. The remaining permutations have at least one fixed point.

What is the probability a random permutation is a derangement?

For larger n, the probability is about 1/e = 0.36788, roughly 37 percent. At smaller sizes it is close but not identical: at n = 6 the probability is exactly 0.36806. So a random permutation is a derangement a bit more than one time in three.

What is the subfactorial of 10?

The subfactorial of 10 is !10 = 1,334,961. This is the nearest integer to 10!/e, so it counts how many of the 10! possible arrangements of ten items leave every item out of its original position. The subfactorial grows quickly as n increases.

Why is !0 equal to 1?

The empty arrangement vacuously has no fixed points, since there are no items that could stay in place, so it counts as one derangement. This value also seeds the recurrence that gives !4 = 9, keeping the sequence consistent from the very start.

Does the probability keep falling as n grows?

No — it oscillates onto 1/e rather than falling steadily. The values are 0.37500 at n = 4, 0.36806 at n = 6, and 0.36788 at n = 10. Each step moves closer to 1/e, alternating above and below it, so the probability settles near 0.36788.

Sources

Related calculators

Factorial Calculator
Exact factorials up to 170! computed with arbitrary-precision integers — no scientific-notation rounding — with the digit count and trailing zeros (Legendre's formula) explained.
Permutations Calculator
Permutations P(n, r), combinations C(n, r), permutations with repetition and n factorial, with large results in compact form.
Absolute Value Calculator
Absolute values and the distance between two numbers on the number line: |a|, |b| and |a - b|, with the sign-stripping logic spelled out.