Subfatorial
- Created by
- Renato Passos, Eng. de Software
- Reviewed by
- Renato Passos, Eng. de Software
Last updated: Apr 18, 2026
Formula
sub-factorial
About this calculator
The subfactorial calculator computes the number of derangements of n elements. A derangement is a permutation where no element appears in its original position. The formula used is !n = n! * Σ_{k=0}^{n} (-1)^k / k!, which can be calculated directly or recursively. This calculator is useful in combinatorics problems, such as the hat problem or the mail problem, where one wants to know how many ways n objects can be rearranged so that none remains in its original place.
To use the calculator, simply enter a non-negative integer n (usually up to 20 due to computational limits). The result is the subfactorial of n, denoted as !n. For example, for n=3, the subfactorial is 2, since the only derangements of {1,2,3} are (2,3,1) and (3,1,2). The calculator can also display the list of derangements for small values, making verification easy.
Practical applications include games of chance, such as the card matching game, and probability problems, like the probability that no one receives their own gift in a Secret Santa exchange. Additionally, subfactorials appear in combinatorial analysis and in Taylor series of exponential functions.
Cautions: For large n, the subfactorial value grows rapidly and may cause overflow in simple calculators. Also, for n=0, the subfactorial is defined as 1 (the empty set is considered a derangement). Ensure you enter only non-negative integers.
Frequently asked questions
What is a subfactorial?
Subfactorial is the number of permutations of n elements where no element is in its original position, also called derangements.
How to calculate the subfactorial of 5?
Enter 5 into the calculator and the result will be 44. This means there are 44 ways to rearrange 5 objects so that none remains in its original place.
What is the difference between factorial and subfactorial?
Factorial (n!) counts all possible permutations, while subfactorial (!n) counts only permutations without fixed points (derangements).
What is the practical use of subfactorial?
It is used in probability problems, such as calculating the chance that no one receives their own gift in a Secret Santa exchange, or in combination games.
What happens if I enter a negative number?
The calculator only accepts non-negative integers. For negative numbers, the result is not defined.