Derangement Calculator
Enter the number of items to find how many derangements exist.
Result
How it is calculated
A derangement of n items is an arrangement where every item ends up in a different place from where it started. The tool builds the count !n with the recurrence !n = (n − 1) × (!(n − 1) + !(n − 2)), starting from !0 = 1 and !1 = 0. It computes the exact integer, shown with thousands separators, and the probability that a random shuffle is a derangement: P = !n ÷ n!, printed with six decimals.
Only whole numbers from 0 to 25 are accepted; a decimal, a negative number or 26 and above gives no result. The edge cases follow the convention: there is 1 way to arrange nothing (n = 0, probability 1), no way for a single item (n = 1, probability 0), and one way for two items (the swap, probability 0.5). For larger n the probability settles close to 1 ÷ e, about 0.3679.
Worked example
Six people leave their hats and none gets their own back. Build the sequence: !0 = 1, !1 = 0, !2 = 1×(0+1) = 1, !3 = 2×(1+0) = 2, !4 = 3×(2+1) = 9, !5 = 4×(9+2) = 44, !6 = 5×(44+9) = 265. Total arrangements: 6! = 720. Probability = 265 ÷ 720 = 0.368056, about 36.8%, close to the limit 1 ÷ e.
Common mistakes
- Confusing !n (derangements) with n! (all arrangements). For 6 items there are 720 arrangements but only 265 derangements.
- Expecting the probability to fall as n grows. It does not: it quickly levels off near 0.3679, so a group of 25 is hardly different from a group of 8.
- Entering the number of pairs or groups rather than the number of items. The tool counts permutations of n distinct items; a gift exchange among 6 people is n = 6.
- Applying it to a draw where some items are identical, or where some people are not allowed to get certain items. The count assumes all items are distinct and the only forbidden outcome is each item in its own spot.
- Trying n = 1 and treating 0 as an error. For one item the only arrangement keeps it in place, so zero derangements is the correct answer.
About this calculator
A derangement is a permutation in which no element ends up in its original position — the classic illustration is the “hat-check problem,” where n people check their hats and every single one is handed back the wrong one. The count of derangements, written !n, follows the formula !n = n! × Σ(−1)^k/k! for k = 0 to n, and also satisfies the tidy recurrence !n = (n−1)(!(n−1) + !(n−2)).
This calculator computes !n for any number of items and the probability that a random permutation happens to be a derangement — a value that converges quickly to 1/e ≈ 36.8% as n grows. It’s a staple example in combinatorics and discrete math courses, and the underlying reasoning shows up in algorithm design and cryptography problems involving permutations with no fixed points, as well as in the well-known “Secret Santa” gift-exchange puzzle.
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)
Secret Santa is a direct use. If you redraw until nobody picks their own name, the chance that one random draw works is about 0.368 for six or more people, so you should expect roughly 2.7 attempts on average. Extra rules, such as partners not drawing each other, are not covered here. Does your draw have restrictions like that? Tell us how you handle them.