Derangement Calculator

Count the permutations where no element stays in its original position, with the total and the chance.

Math and PercentUpdated 2026-11-182 min read
Derangement Calculator
A whole number from 0 to 100.
Derangements of n
...
All permutations...
Share of permutations...

What it does

A derangement is a rearrangement in which nothing ends up where it started. If five letters go into five addressed envelopes, a derangement is a way to seal them so that no letter matches its own envelope. The count is written with a leading exclamation mark, such as !5.

The problem is classical. It appears in a pond game of rencontres and in the secret Santa question of drawing names without drawing yourself. Pierre Raymond de Montmort studied it in the early eighteenth century, and the associated probabilities settle near one over e as the number of objects increases.

Counting by inclusion and exclusion gives a formula with alternating terms. The recurrence used here is easier to compute: !n equals (n - 1) times the sum of !(n - 1) and !(n - 2). Starting from !0 = 1 and !1 = 0, every later value follows by integer multiplication and addition.

This page reports the derangement count, the total number of permutations, and the percentage of arrangements that are clean. For five objects there are 44 clean arrangements out of 120, or 36.67 percent, which is already close to the limiting value of about 36.79 percent.

All results are exact integers up to n = 100. The percentage is computed from those integers and shown with two decimals, so it stays accurate even when the counts are very large.

How to use

  1. Enter the number of objects n from 0 to 100.
  2. Read the derangement count in the main result box.
  3. Check the total number of permutations beside it.
  4. Read the chance to see how common a clean shuffle is.
  5. The page opens with n = 5 to match the worked example.
  6. Try n = 10 to see the percentage settle near 36.79 percent.

Formula

!n = (n - 1) x (!(n - 1) + !(n - 2)), with !0 = 1 and !1 = 0
n
The number of objects and positions.
!n
The number of permutations with no fixed point.
n!
The total number of permutations of n objects.

An equivalent expression uses inclusion and exclusion: !n = n! times the sum of (-1)^k / k! from k = 0 to n. That sum approaches one over e, which is why the percentage tends to 36.79 percent. The recurrence is preferred here because it uses whole numbers only and stays exact for every allowed input.

Worked example

Example: five objects

The default input is n = 5.

  1. Start from !0 = 1 and !1 = 0.
  2. Compute !2 = 1 x (0 + 1) = 1.
  3. Compute !3 = 2 x (1 + 0) = 2.
  4. Compute !4 = 3 x (2 + 1) = 9.
  5. Compute !5 = 4 x (9 + 2) = 44.
  6. The total number of orders is 5! = 120.
  7. The tool reports 44 derangements, 120 permutations, and 36.67 % clean shuffles.

Reference table

Derangements and their share
n!nn!Chance
21250.00 %
32633.33 %
492437.50 %
54412036.67 %
626572036.81 %
71854504036.79 %

Limits

  • Only perfect matchings of equal sized sets are counted.
  • The share is shown with two decimals and is not an exact rational value.
  • Inputs above 100 are rejected so the displayed integers stay readable.
  • Extra restrictions such as forbidden pairs are outside this calculation.

Common mistakes

  • Using n! times one over e without rounding, which gives a non integer count.
  • Starting the recurrence at !1 = 1, which shifts every later value.
  • Confusing derangements with permutations that have exactly one fixed point.
  • Assuming the percentage keeps oscillating instead of settling.
  • Forgetting that !1 is zero because one object must stay in place.

Try it yourself

Quick checks. Answers sit tucked under each question.

How many derangements does three objects have?

!3 = 2 x (1 + 0) = 2 out of 6 permutations, a chance of 33.33 %.

What is !6?

!6 = 5 x (44 + 9) = 265, and 265 / 720 is about 36.81 %.

What is !5?

!5 = 4 x (9 + 2) = 44 out of 120 orders, or 36.67 %.

Questions

What is a fixed point?

A position where the element after rearranging is the same as before.

Why is the notation an exclamation mark before n?

It is called the subfactorial and is written with the mark in front to distinguish it from n factorial.

What is the limiting probability?

One over e, roughly 36.79 percent, reached quickly as n grows.

How is this used in a gift draw?

A valid draw is exactly a derangement of the participant names.

Is the count always an integer?

Yes. The recurrence uses only whole numbers, so no rounding is needed.

What input range works here?

Whole numbers from 0 through 100, with a clear error outside that range.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.