Derangements !n
- Created by
- Renato Passos, Eng. de Software
- Reviewed by
- Renato Passos, Eng. de Software
Last updated: Apr 18, 2026
Formula
derangements
About this calculator
The derangements (subfactorial) calculator determines the number of permutations of n elements where no element appears in its original position. It is useful in combinatorial problems involving disarrangements, such as the classic hat problem. The approximate formula is !n ≈ n!/e, where e is the base of natural logarithms.
The exact calculation uses the subfactorial formula: !n = n! * Σ_{k=0}^{n} (-1)^k / k!. For large n, the approximation by n!/e is very accurate. This calculator provides both the exact value and an approximation, making it easy to understand the result.
Use this calculator in situations such as: arranging samples so that none is in its original position, distributing gifts so that no one receives their own, or in probability problems where one wants to avoid coincidences. It is an essential tool for students and professionals in mathematics, statistics, and computer science.
Caution: for very large n (above 170), the factorial exceeds common numeric representation limits. The calculator uses arbitrary precision arithmetic up to a certain limit, but for n > 170, only the approximation is provided. Also, remember that derangements differ from random permutations.
Frequently asked questions
What is a derangement?
A derangement is a permutation of elements where no element appears in its original position. For example, for 3 elements, a derangement moves all elements to different positions from the initial ones.
How to calculate derangements for large n?
For large n, use the approximation !n ≈ n!/e. The calculator provides this approximate value when the exact one is not possible due to precision limits.
What is the difference between derangements and permutations?
Permutations are all ways to order elements, while derangements are a subset where no element is in its original position. The number of derangements is much smaller than permutations.
Does the calculator work for n = 0?
Yes, for n = 0, the derangement is 1 (empty set). The formula also returns 1.
Why is the result an integer?
The subfactorial is always an integer because the formula involves factorial and a sum of terms that result in an integer. The approximation by n!/e is rounded to the nearest integer.