Subfactorial Calculator
Find the number of derangements of n items.
Result
How it is calculated
The subfactorial !n counts derangements: arrangements of n distinct items in which no item ends up in its original position. The tool uses the recurrence !n = (n − 1) × (!(n − 1) + !(n − 2)) with !0 = 1 and !1 = 0. Equivalently, !n is the nearest whole number to n! / e.
n is cut to a whole number and must be between 0 and 170. Values grow quickly, and above roughly n = 18 the intermediate numbers exceed what ordinary floating-point arithmetic holds exactly, so only the leading digits of very large results can be trusted. For n = 1 the answer is 0, because a single item cannot be moved.
Worked example
For n = 5: !0 = 1, !1 = 0. !2 = 1 × (0 + 1) = 1. !3 = 2 × (1 + 0) = 2. !4 = 3 × (2 + 1) = 9. !5 = 4 × (9 + 2) = 44. Check: 5! / e = 120 / 2.71828 ≈ 44.15, nearest whole number 44. The tool shows 44.
Common mistakes
- Confusing !n with n!: for 5 they are 44 and 120.
- Thinking !n counts permutations where at least one item moves; that would be n! − 1. A derangement needs every item to move.
- Reading "!5" as a factorial from other notation; here the exclamation mark comes first.
- Trusting every digit of the answer for big n; results above about n = 18 are approximate.
About this calculator
The subfactorial !n, also called the number of derangements of n, counts the permutations of n objects in which no object ends up in its original position. It's defined by !n = n! · Σ(k=0 to n) (−1)^k/k!, and grows very close to n!/e for large n — in fact !n is the nearest integer to n!/e. For example !4 = 9: out of the 24 permutations of 4 items, only 9 leave every item out of place.
The classic illustration is the "hat-check problem" (or "misaddressed letters problem"): if n people check their hats and they're returned randomly, !n is the number of ways every single person gets the wrong hat back. Combinatorics students, probability courses and puzzle enthusiasts use subfactorial calculations to solve derangement problems, and the concept extends into cryptography and coding theory wherever "nothing stays in its original slot" permutations matter.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
A useful sanity check is the ratio !n divided by n!. It settles near 0.368, which is 1/e, almost immediately: for n = 5 it is 44/120, about 0.367. So a random shuffle of even a few items leaves nobody in place roughly one time in three. This is the maths behind secret Santa draws where no one may pick their own name. Which derangement puzzle brought you here?