InfyCalculator
➗

Derangement Calculator (!n)

Count derangements — permutations where nothing stays in its original place — with the subfactorial !n, plus the probability of a random derangement.

n (items)
Loading calculator…

How it works

!n = (n − 1) · ( !(n−1) + !(n−2) ), !0 = 1, !1 = 0 · !n ≈ n!/e

A derangement is a permutation in which no element ends up in its starting position — the “nobody gets their own hat back” count. The subfactorial !n follows a tidy recurrence and, remarkably, !n / n! converges to 1/e ≈ 36.79% almost immediately, so for any decent n a random shuffle is a derangement about 37% of the time. It appears in the hat-check problem, secret-santa constraints and the inclusion–exclusion principle.

Worked example

For n = 5: !5 = 44. Since 5! = 120, the probability a random permutation is a derangement is 44 / 120 = 36.67%, already very close to 1/e.

Sources: Derangement — Wikipedia

Frequently asked questions

What exactly is a derangement?

A permutation where every item moves — none stays in its original position. If five people swap hats so that nobody gets their own back, that is a derangement.

Why does the probability approach 1/e?

By inclusion–exclusion, !n/n! = Σ (−1)ᵏ/k!, which is the Taylor series for e⁻¹. It converges so fast that even n = 5 is within a fraction of a percent of 36.79%.

What are !0 and !1?

!0 = 1 (the empty arrangement trivially deranges nothing) and !1 = 0 (a single item must stay put, so no derangement exists).

Related calculators

This calculator is for educational purposes. Double-check important results before acting on them.