Derangement Calculator

Calculate !n (subfactorial) - the number of permutations where no element appears in its original position.

Calculate !n

!5 (Derangements)

44

5! (Permutations)

120

Probability of Derangement

36.6667%

!5 / 5! = 0.36666667

Limit as n → ∞

36.7879%

1/e ≈ 0.36787944

Derangement vs Factorial

n!nn!!n/n!
0111
1010.000000
2120.500000
3260.333333
49240.375000
5441200.366667
62657200.368056
7185450400.367857
814833403200.367882
91334963628800.367879
10133496136288000.367879
1114684570399168000.367879

Formulas

Recurrence

!n = (n-1)(!(n-1) + !(n-2))

Inclusion-Exclusion

!n = n! × Σ(-1)^k/k!

Nearest Integer

!n = round(n!/e)

Limit

lim(!n/n!) = 1/e

The Hat Check Problem

If n people check their hats and the hats are returned randomly, what is the probability that no one gets their own hat back? The answer is !n/n!, which approaches 1/e ≈ 36.79% as n increases. Remarkably, this probability is nearly constant for n ≥ 4.