Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

Permutations




Permutations: Understanding Ordered Arrangements

Permutations are arrangements where order matters. As we discussed on the main combinatorics page, this is what distinguishes permutations from combinations.

On this page, we'll explore the key permutation scenarios, including Full Permutation (arranging all n distinct elements), Permutation with Repetition (arrangements where certain elements can repeat), Permutation without Repetition (selecting and arranging r elements from n options), and Circular Permutation (arrangements around a circle where rotations are identical).

Each scenario has specific formulas and real-world applications. Ready to dive into the details, or want to compare with combinations where order doesn't matter?

Mastering these permutation types gives you the tools to solve ordering problems across mathematics, computer science, and everyday scenarios. The key is recognizing which type fits your specific situation.




The Logic behind permutations

Lining things up in order gets out of hand quickly.
Two items can stand in a row in 22 ways: AB or BA. Three letters A, B, C already give more, and the list is easy to get wrong — skip one order or write another twice. Ten books on a shelf could not be listed by hand at all. There has to be a way to count the orders without writing them out.
Original set 2! = 2 ways All possible arrangements Original set 3! = 6 ways All possible arrangements Original set 4! = 24 ways All possible arrangements Permutation: Arrange ALL items, order matters Take n distinct items → arrange them in every possible order → get n! arrangements
Building the orders one position at a time gives the count.
Fill the three places of the row in turn. The first place can take any of the 33 letters. Once it is filled, 22 letters are left for the second place. Then 11 letter is left for the third. Every first choice combines with every second choice and every third, so the counts multiply.
Permutations of ABC: Step-by-Step A B C First choice: A B C 3 options to choose first ball Second choice: B C A C A B 2 options to choose second ball Third choice: C B C A B A 1 option left for the last ball Final permutations: ABC ACB BAC BCA CAB CBA 3! = 3 × 2 × 1 = 6 total permutations
Factorial of 3
3×2×1=6(n!)3\times 2 \times 1 = 6 (n!)
Six orders: ABC, ACB, BAC, BCA, CAB, CBA — exactly the list above, with nothing missed and nothing repeated.
Nothing in that count was chosen; every factor was forced.
Each factor is one less than the one before because a letter, once placed, cannot be used again. The factors multiply because the choices are made in sequence — the multiplication principle. Nothing depended on there being three letters: with nn items the first place has nn options, the next n−1n - 1, and so on down to 11.
items nchoices, position by positionarrangements
111
22 × 12
33 × 2 × 16
44 × 3 × 2 × 124
55 × 4 × 3 × 2 × 1120
The definition
A permutation of a set of distinct items is an arrangement of all of them in a definite order. For nn distinct objects, the number of permutations is:
Factorial
n!=n×(n−1)×(n−2)×⋯×2×1.n! = n \times (n−1) \times (n−2) \times \dots \times 2 \times 1.
Learn more about this formula: Factorial →
The product n×(n−1)×⋯×1n \times (n - 1) \times \dots \times 1 is the factorial n!n!; for 33 letters, 3!=63! = 6.
A permutation is an ordered arrangement, and n! is a count of them.
Each permutation is a sequence: ABC and BAC contain the same letters but are different permutations, because order is the whole point. In every type of permutation, the order of arrangement matters — that is exactly what separates permutations from combinations, where only the group counts. The number n!n! is how many such sequences there are.
The multiplying generalizes; the rest was particular to this example.
What generalizes is the mechanism: fill positions one by one and multiply the options at each step. What was particular: every item was used, every item was different, none could repeat, and the row had a first and last place. Change any of these — use only some items, allow identical items or repetition, seat them in a circle — and the factors change, which is what the types of permutations below sort out. And the count grows fast: 44 items already give 2424 orders, and 1010 give 3,628,8003{,}628{,}800.
P(4) = 4! = 24Complete · 24 / 24SOURCE (n = 4)1234BUILD AREA#1#2#3#4COMPLETED24 / 241123412431324134214231432221342143231423412413243133124314232143241341234214412341324213423143124321
All 2424 orders of 44 items, grouped by the item in first place: 44 groups of 66, the 3!=63! = 6 orders of the rest. The same state is on the full permutation visualizer.
The rest of the page goes through the types of permutations — full, with identical items, partial, with repetition, circular — their notation, and derangements, where no item may stay in its place.

Types of Permutations

Although in all types of permutations the order of arrangement matters, the key differences between them arise from other considerations: Can items be repeated? Are some items identical? Is the arrangement linear or circular? The table below summarizes these distinctions, showing how different scenarios lead to different counting formulas.

Permutation Scenarios

ScenarioOrder Matters?Repetition?Identical Items?Arrangement TypeFormulaExample
Full permutationYesNoNoLinearn!n!Arrange 6 books in a row
Partial permutationYesNoNoLinearn!(n−r)!\frac{n!}{(n-r)!}Arrange 3 of 10 runners
Permutation with repetitionYesYesNoLinearnrn^r4-digit PIN code
Permutation with identical itemsYesN/AYesLinearn!n1! n2!…nk!\frac{n!}{n_1! \, n_2! \dots n_k!}Rearrange "BALLOON"
Circular permutationYesNoNoCircular(n−1)!(n-1)!Seat 5 people around a table


By addressing these additional questions, we can classify permutations into several types, each with its own counting method. Understanding these distinctions helps in correctly applying the appropriate formula for a given arrangement problem.

Permutation (Full)

Full Permutation applies when you arrange all distinct items in a specific order with no repetitions allowed.

Property Full Permutation
Use all items ✓
Order matters ✓
Identical items ✗
Repetitions ✗
Linear arrangement ✓

Full Permutation — Examples:
Arranging all books on a shelf, deciding the lineup of all players in a team, organizing all photos in an album, setting the order of speakers in a presentation, ordering all tasks in a workflow, ranking all competitors in a contest, scheduling all meetings in a day, sorting all files in a folder.

P(3) = 3! = 6Complete · 6 / 6SOURCE (n = 3)123BUILD AREA#1#2#3COMPLETED6 / 6112313222132313312321
All 3! = 6 arrangements of three items

Three distinct items, every order they can stand in: 3 choices for the first place, 2 for the second, 1 for the last, and the six results laid out in groups by their first item. Each group has the same size because whatever goes first, the rest can still be ordered in 2! ways. Build the arrangements for 4 and 5 items on the full permutation visualizer.

Every extra item multiplies the count again: 4 items give 24 arrangements, 5 give 120.

The intuition and logic we use for this kind of permutation has been explained pretty well in previous section and it works basically for all types of permutations.
Just in case of full permutations (unlike in other types) no further modifications needed and the calculation is simple.

Notation:
In combinatorics, we use specific notation to represent different types of permutations.
For arranging rr objects selected from nn distinct objects, the standard notation is P(n,r)P(n,r) or nPr_nP_r.
When applied to full permutations, apparently r=nr=n (because we use all the items ), and the notation turns into :

P(n,n)P(n,n)

or nPn_nP_n

or simply P(n)P(n).

Learn more about combinatorial notations and symbols here →

Formula:
The number of possible results is calculated by the formula :
Full Permutation
P(n)=n!P(n)=n!
Learn more about this formula: Full Permutation →
Product of all integers from nn down to 11.
Where nn is the number of items to arrange.

Use combinatorics calculator →

Fact: π\pi and ee estimate 10!10! within 1%
Stirling's formula n!≈2πn(ne)nn! \approx \sqrt{2\pi n}\left(\frac{n}{e}\right)^n gives about 3,598,6963{,}598{,}696 for n=10n = 10, less than 1%1\% below 10!=3,628,80010! = 3{,}628{,}800. Its relative error is close to 112n\frac{1}{12n}, so it keeps shrinking as nn grows.

The factorial soon outgrows every everyday quantity. Each new item multiplies the count by a larger number than the item before it did, so n!n! eventually overtakes 2n2^n, 10n10^n and any other fixed number raised to the power nn. Already 13!=6,227,020,80013! = 6{,}227{,}020{,}800 is more than six billion, and 20!20! has 1919 digits. Most pocket calculators give up at 70!70!, the first factorial above 1010010^{100}, because they show only two digits for the power of ten.


Permutation with Identical Items

Permutation with Identical Items applies when arranging all items where some identical elements appear multiple times in your collection. Classic examples include arranging all letters in words like "MISSISSIPPI" or organizing all colored balls when you have multiple balls of the same color.

Property Permutation with Identical Items
Use all items ✓
Order matters ✓
Identical items ✓
Repetitions ✗
Linear arrangement ✓

Permutation with Identical Items — Examples:
Rearranging letters in the word “BALLOON,” organizing colored balls where some colors repeat, sequencing identical files and unique ones in storage, arranging identical chairs and distinct tables in a layout, ordering repeated ingredients in a recipe list.

Notation:

(nn1,n2,…,nk)\binom{n}{n_1, n_2, \ldots, n_k}

or P(n;n1,n2,n3,…,nk)P(n; n_1, n_2, n_3, \ldots, n_k)

or Pnn1,n2,n3,…,nkP_n^{n_1, n_2, n_3, \ldots, n_k}

Learn more about combinatorial notations and symbols here →

Formula:

To calculate the number of possible arrangements
Permutation with Identical Items
(nn1,n2,…,nk)=n!n1!n2!…nk!\binom{n}{n_{1},n_{2},\dots,n_{k}} = \frac{n!}{n_{1}!n_{2}!\dots n_{k}!}
Learn more about this formula: Permutation with Identical Items →
The multinomial coefficient counts distinct arrangements of nn items split into groups of sizes n1,n2,…,nkn_{1},n_{2},\dots,n_{k}.

Use combinatorics calculator →

Pitfall: Missing a repeated letter
Computing 11!4!⋅4!=69,300\frac{11!}{4! \cdot 4!} = 69{,}300 for MISSISSIPPI divides out the Is and the Ss but not the two Ps, so every word is counted twice. With 2!2! in the denominator, the count is 34,65034{,}650.

MISSISSIPPI is the standard case for this formula. Its 1111 letters fall into four groups: one M, four Is, four Ss and two Ps, so n=11n = 11 and the group sizes are 1,4,41, 4, 4 and 22. Swapping two letters of the same group gives back the same word, and the denominator removes these swaps group by group. A letter that appears only once forms a group of size one and contributes 1!=11! = 1.



Permutations: All Different vs. Some Identical Items Case 1: All Different Items 3! = 6 permutations Initial Set: Case 2: Some Identical Items 3!/2! = 3 permutations Initial Set: RGB RBG GRB GBR BRG BGR RRB RBR - Canceled BRR RBR BRR - Canceled RRB - Canceled All Different Items: • Each ball is unique (Red, Green, Blue) • Every arrangement creates a distinct permutation • Formula: n! = 3! = 6 permutations • All 6 arrangements are counted Some Identical Items: • Two red balls are identical, one blue ball is unique • Swapping identical red balls gives same arrangement • Formula: n!/k! = 3!/2! = 3 permutations • Red X marks duplicate arrangements Identical items reduce total permutations Legend: Valid permutation (no marking) Duplicate arrangement - Canceled
Permutations: All Different vs. Some Identical Items Case 1: All Different Items 3! = 6 permutations Initial Set: Case 2: All Identical Items 3!/3! = 1 permutation Initial Set: RGB RBG GRB GBR BRG BGR RRR RRR - Canceled RRR - Canceled RRR - Canceled RRR - Canceled RRR - Canceled All Different Items: • Each ball is unique (Red, Green, Blue) • Every arrangement creates a distinct permutation • Formula: n! = 3! = 6 permutations • All 6 arrangements are counted All Identical Items: • All three red balls are identical • Any rearrangement gives the exact same result • Formula: n!/n! = 3!/3! = 1 permutation • Only 1 distinct arrangement possible Identical items reduce total permutations Legend: Valid permutation (no marking) Duplicate arrangement - Canceled
2 red, 1 blue 3!/(2!×1!) = 3 Identical items reduce count 2 red, 2 blue 4!/(2!×2!) = 6 Two types of repetition 3 red, 1 blue, 1 green ⋮ 5!/(3!×1!×1!) = 20 Only 10 shown above Permutations with Identical Items Formula: n! / (n₁! × n₂! × ... × nₖ!) where nᵢ = count of each identical type
Swapping identical items changes nothing, so each group's factorial in the denominator removes exactly those swaps.

Partial Permutation without Repetition

Partial Permutation without Repetition applies when selecting and arranging only some items from a larger collection, with all items being distinct. Classic examples include choosing and ordering contestants from a group or selecting and arranging books from a library shelf.

Property Partial Permutation without Repetition
Use all items ✗
Order matters ✓
Identical items ✗
Repetitions ✗
Linear arrangement ✓

Partial Permutation (without repetition) — Examples:
Selecting and ordering finalists from a group of contestants, arranging a subset of books on a display, picking and sequencing players for a relay team, choosing and ordering questions for an interview, organizing a limited set of tasks for a project phase.

Notation:

Most common:

P(n,r)P(n,r)

Alternative notations:

nPr {}^nP_r

AnrA_n^r

nPr\text{nPr}

Learn more about combinatorial notations and symbols here →

Formula:
The number of arrangements for Partial Permutation without Repetition is
Partial Permutation without Repetition
P(n,r)=n!(n−r)!P(n,r) = \frac{n!}{(n-r)!}
Learn more about this formula: Partial Permutation without Repetition →
Where n!n! counts all arrangements, dividing by (n−r)!(n-r)! removes the unused positions.

Use combinatorics calculator →

Pitfall: Dividing by r! when order matters
Using (103)=120\binom{10}{3} = 120 for gold, silver and bronze among 10 runners counts only which three runners win a medal. Each such trio can receive the three medals in 3!=63! = 6 orders, so the count is P(10,3)=720P(10, 3) = 720.

A race with 10 runners and medals for the first three places is the typical case: n=10n = 10 runners and r=3r = 3 places. The formula keeps only the first rr factors of 10!10!, one for each place to fill: 1010 choices for the gold, 99 for the silver and 88 for the bronze. The remaining factors 7⋅6⋯17 \cdot 6 \cdots 1 are exactly the (n−r)!=7!(n - r)! = 7! that the division removes.

Partial Permutations: P(4,2) Selecting and arranging 2 items from 4 available items P(4,2) = 4!/(4-2)! = 4!/2! = 24/2 = 12 permutations Available Items: Choose 2 and arrange them All 12 Partial Permutations: Starting with Red: Starting with Green: Starting with Blue: Starting with Yellow: Partial Permutations Explained: Step 1: Choose the first position - 4 choices (any of the 4 colored balls) Step 2: Choose the second position - 3 remaining choices Total: 4 × 3 = 12 different ordered pairs Key point: Order matters! Red-Green is different from Green-Red Formula: P(n,r) = n!/(n-r)! where n=4 items available, r=2 items selected
n = 3 items choose r = 2 P(3,2) = 6 3!/(3-2)! = 6 n = 4 items choose r = 2 n = 4 items choose r = 2 P(4,2) = 12 4!/(4-2)! = 12 n = 5 items choose r = 2 P(5,2) = 20 5!/(5-2)! = 20 Permutation without Repetition: Select r from n, order matters Formula: P(n,r) = n!/(n-r)! - Choose r items from n, arrange them in order
Filling only rr places keeps the first rr factors of n!n! and drops the rest.

Permutation Notation

Notation

Permutation Notation

Three marks carry every count on this page: the exclamation that multiplies downward, the two-letter family that orders selections, and the same exclamation moved out front to count the restless. Each scenario section keeps its own Notation block for the variant spellings.
The choose-family marks (nr)\binom{n}{r} and C(n,r)C(n, r) belong to the binomial coefficient; the set-size bars behind the counting arguments to cardinality.
n!n!
n factorial
The postfix count of complete rearrangements: n!=n×(n−1)×⋯×1n! = n \times (n-1) \times \cdots \times 1, introduced in The Logic behind permutations above. The convention 0!=10! = 1 is load-bearing — it keeps every counting formula honest at the edges.
CasesThe mark binds tight — 2n!2n! means 2⋅(n!)2 \cdot (n!), and (2n)!(2n)! needs its brackets; stacked marks are different animals: (n!)!(n!)! iterates, while n!!n!! skips every second factor (the double factorial), not a repeat.
Do not confusePunctuation. A sentence ending on 55 with an exclamation and the operator in 5!5! share a glyph — and in programming ! negates; position and context carry the meaning.
P(n,r)P(n, r) · nPr_nP_r
P n r; n permute r
The arrangement-count family: P(n,r)=n!(n−r)!P(n, r) = \frac{n!}{(n - r)!} orders rr items chosen from nn — functional P(n,r)P(n, r) in texts, subscripted nPr_nP_r on calculator keys, as the Notation blocks of Permutation (Full) and Partial Permutation without Repetition above list.
CasesAnrA_n^r — the Arrangements letter of French and Russian textbooks, same count in a different alphabet; the full case collapses the second argument: P(n,n)=P(n)=n!P(n, n) = P(n) = n!.
Do not confuseThe choose family. P(n,r)P(n, r) counts ordered selections, (nr)\binom{n}{r} unordered ones — they differ by exactly the factor r!r!, and the binomial coefficient owns the other side of that ledger.
!n!n · DnD_n
subfactorial n; derangements of n
The factorial's mirror image: !n!n counts permutations that leave nothing in place — the prefix position is the entire distinction, as Derangement below explains. DnD_n is the older spelling, still common.
CasesThe two interchange freely — !5=D5=44!5 = D_5 = 44; the prefix form reads badly mid-sentence, which is precisely what keeps the subscripted DnD_n alive in running text.
Do not confusen!n! read backwards. !4=9!4 = 9 while 4!=244! = 24 — position flips the meaning entirely, and a hasty transcription trades all arrangements for only the restless ones.

Permutation with Repetition

Permutation with Repetition applies when arranging items where you can reuse the same element multiple times during the arrangement process. Classic examples include creating PIN codes where digits can repeat, or forming passwords where letters can be used multiple times.

Property Permutation with Repetition
Use all items ✗
Order matters ✓
Identical items ✗
Repetitions ✓
Linear arrangement ✓

Permutation with Repetition — Examples:
Generating PIN codes from digits, creating letter sequences for passwords, setting the dials of a combination lock, composing license plate numbers, assigning seats with multiple people allowed in the same category.

Fact: A combination lock counts permutations
A lock set to 4-7-2 does not open at 2-7-4, and two dials may show the same digit, so its codes are ordered and may repeat: three dials give 103=100010^3 = 1000 codes. A true combination of three different digits would leave only (103)=120\binom{10}{3} = 120.

The combination lock in this list is a small case of the same count. A padlock with three dials, each showing the digits 0 to 9, has one position for every dial and one option for every digit, so it fits the formula below with n=10n = 10 and r=3r = 3. Nothing stops two dials, or all three, from showing the same digit, and a code such as 0-0-0 is as valid as any other.

Notation:

Permutation with repetition (positions)

Prep(n,r)P_{\text{rep}}(n,r)

Alternative notations:

P‾(n,r)\overline{P}(n,r)

P(r)(n)P^{(r)}(n)

nPr(r) {}^nP^{(r)}_r

Learn more about combinatorial notations and symbols here →

Formula:
Total number of permutations with repetition allowed, filling rr positions from nn items, is:
Permutation with Repetition
Prep(n,r)=nrP_{\text{rep}}(n,r)=n^{r}
Learn more about this formula: Permutation with Repetition →
Where each of the rr positions can be filled in nn ways.


Use combinatorics calculator →

Pitfall: Swapping the base and the exponent
Writing 410=1,048,5764^{10} = 1{,}048{,}576 for a 4-digit PIN treats it as 10 positions with 4 options each. Four positions with 10 digits each give 104=10,00010^4 = 10{,}000 codes.

A 4-digit PIN is the standard example. Each of the r=4r = 4 positions can hold any of the n=10n = 10 digits, whatever was entered before, so the same digit may appear in several positions, as in 0707 or 1111. The count is built position by position, exactly as for a full permutation, except that the number of options never shrinks from one position to the next.


Permutations with Repetition Selecting 2 items from 4 available items (repetition allowed) nr = 42 = 16 permutations Available Items (can be reused): Choose 2 (repetition allowed) All 16 Permutations with Repetition: Starting with Red: Starting with Green: Starting with Blue: Starting with Yellow: Permutations with Repetition Explained: Step 1: Choose the first position - 4 choices (any color, can be reused) Step 2: Choose the second position - 4 choices (still all colors available) Total: 4 × 4 = 16 different ordered pairs Formula: nr where n=4 items available, r=2 positions to fill Note: The diagonal (RR, GG, BB, YY) shows repetition is allowed

Circular Permutation

Circular Permutation applies when arranging items around a circle where rotations are considered identical arrangements. Classic examples include seating people around a round table or arranging objects in a circular pattern.

Property Circular Permutation
Use all items ✓
Order matters ✓
Identical items ✗
Repetitions ✗
Linear arrangement ✗

Circular Permutation — Examples:
Arranging guests around a round table, seating participants in a circular panel, ordering beads on a ring that is never flipped over, organizing tasks in a repeating cycle, setting positions for players in a circular game arrangement.

Notation:
Circular permutation

Pcirc(n)P_{\text{circ}}(n)

Alternative notations

Pcyclic(n)P_{\text{cyclic}}(n)

n!n\frac{n!}{n}

Learn more about combinatorial notations and symbols here →

Formula:

The total number of possible circular arrangements is
Circular Permutation
Pcirc(n)=(n−1)!P_{\text{circ}}(n) = (n-1)!
Learn more about this formula: Circular Permutation →
If nn is a total number of items to arrange then fixing one item reduces circular arrangements to (n−1)!(n-1)! linear ones.

Use combinatorics calculator →

Pitfall: Using n! for a round table
Counting 5!=1205! = 120 seatings for 5 people at a round table counts each seating 5 times, once for every turn of the table. Dividing by 5 gives 4!=244! = 24.

Five people at a round table show how this works. Fix one of them in a seat; every seating can then be read from that seat clockwise, and the other four people fill the remaining seats in any order. Turning the whole table moves everyone at once but leaves each person with the same neighbours on the left and on the right, which is why a turn does not create a new arrangement.


Original set (2-1)! = 1 way Rotations are same Original set (3-1)! = 2 ways Fix one position Original set (4-1)! = 6 ways Red fixed at top Circular Permutation: Arrange in circle, rotations are identical Fix one item's position → arrange remaining (n-1) items → get (n-1)! arrangements
Circular Permutations of ABC with Connected Balls ABC group: A B C B C A C A B These three arrangements are identical (just rotated clockwise) ACB group: A C B C B A B A C These three arrangements are identical (just rotated clockwise) In circular permutations, rotations are considered the same arrangement.
A B C A B C A C B ABC = BCA = CAB ACB = CBA = BAC These three arrangements are identical because in circular permutations, only relative order matters These three arrangements are identical because rotations of the same circular order are equivalent
A circle has no first seat, so fixing one item turns the circle into a row of the remaining n−1n - 1.

Derangement


A derangement is a permutation with an added constraint: no element appears in its original position. The other five permutation types vary the question of which arrangements to count — all items or a subset, with or without repetition, linear or circular. The derangement varies the constraint on the arrangement itself: same items, same order-matters property, same linear shape, with the extra requirement that every item must have moved.

The classical motivation is the hat-check problem. nn guests check nn hats, and the attendant returns them in a random order. In how many of those orderings does no guest receive their own hat? Each such ordering is a derangement of the nn hats.

Notation


Two notations are in common use:

• !n!n — the subfactorial, the modern standard. The exclamation precedes the operand, mirroring the factorial in reverse.
• DnD_n — an alternative notation, common in older texts.

The two are interchangeable.

Formula


The explicit formula is

Derangement
!n=n!∑k=0n(−1)kk!.!n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}.
Learn more about this formula: Derangement →


It is derived by applying the inclusion–exclusion principle to the set of all permutations: start with n!n! total, subtract those that fix at least one specific position, add back those that fix at least two, and continue with alternating signs through all nn positions. The full derivation lives on the inclusion–exclusion page; the permutations page uses the result.

A recursive form is also useful for computation:

Derangement Recurrence
!n=(n−1)(!(n−1)+!(n−2)),!0=1,!1=0.!n = (n-1) \bigl( !(n-1) + !(n-2) \bigr), \quad !0 = 1, \quad !1 = 0.
Learn more about this formula: Derangement Recurrence →


The asymptotic behavior of the formula is striking. As n→∞n \to \infty,

Derangement Asymptotic Limit
lim⁡n→∞!nn!=1e≈0.367879.\lim_{n \to \infty} \frac{!n}{n!} = \frac{1}{e} \approx 0.367879.
Learn more about this formula: Derangement Asymptotic Limit →


The proportion of permutations that are derangements approaches a fixed limit rather than vanishing or filling the space — for any sufficiently large nn, roughly 36.8%36.8\% of all permutations of nn items are derangements.

Small Values


The first few subfactorials:

• !1=0!1 = 0 — with one item, the only permutation leaves it in place
• !2=1!2 = 1 — the swap
• !3=2!3 = 2
• !4=9!4 = 9
• !5=44!5 = 44
• !6=265!6 = 265

Example
In the hat-check problem with 4 guests, the number of orderings in which no guest receives their own hat is
!4=4!∑k=04(−1)kk!=24(1−1+12−16+124)=9.!4 = 4! \sum_{k=0}^{4} \frac{(-1)^k}{k!} = 24 \left(1 - 1 + \tfrac{1}{2} - \tfrac{1}{6} + \tfrac{1}{24}\right) = 9.
Out of the 4!=244! = 24 possible orderings of the four hats, exactly 9 satisfy the no-fixed-point condition.

Pitfall: Subtracting only the single fixed points
Taking 24−4⋅3!=024 - 4 \cdot 3! = 0 for the 4 hats removes every order that returns two or more hats several times. Adding back pairs and subtracting triples gives 24−24+12−4+1=924 - 24 + 12 - 4 + 1 = 9.

Behind the five terms of the sum are the counts of orders with chosen hats fixed. Fixing the hat of one chosen guest leaves 3!=63! = 6 orders, and there are 44 guests to choose. Fixing a chosen pair leaves 2!=22! = 2 orders for each of the (42)=6\binom{4}{2} = 6 pairs, a chosen three leaves 11 order for each of the 44 triples, and all four fixed is the single order that returns every hat. An order that returns two hats correctly is among the orders counted for each of those two guests.

The factorial calculator also computes the subfactorial !n!n, which counts derangements directly.
Six ways to hand back three hats; two leave no guest with their ownguestABCown hatsorder 1ABC3order 2ACB1order 3BAC1order 4BCA0order 5CAB0order 6CBA1a guest gets their own hat!3 = 3!(1 − 1 + 1/2 − 1/6) = 22 of the 3! = 6 orders give nobody their own hat: !3 = 2
Three guests, three hats

Guests A, B and C each checked a hat, and the six rows are every order the hats can come back in. A red circle marks a guest who got their own hat back. Four orders return at least one hat correctly; only B C A and C A B leave every guest holding someone else’s hat — the two derangements, so !3 = 2. The alternating sum under the table is the formula for n = 3: start from all 3! orders and correct for the ones that fix a place.

Both derangements are rotations: in B C A every hat moves one seat one way, in C A B one seat the other way.
Beyond a handful of items, the share of orders that move every item settles near 11 in ee, about 37%37\%.

Common Pitfalls


Five mistakes come up again and again when counting permutations. Each is marked where it happens in the sections above; here each is worked through in full, with the wrong and the right working side by side.

Missing a repeated letter

In a word with several repeated letters, the factorial of one group or of two groups goes into the denominator and another group is left out. Every arrangement is then counted once for each order of the letters in the missing group.

Wrong working: MISSISSIPPI has 1111 letters with four Is, four Ss and two Ps, and the count is given as 11!4!⋅4!=39,916,800576=69,300\frac{11!}{4! \cdot 4!} = \frac{39{,}916{,}800}{576} = 69{,}300.

Right working: every repeated group gets its factorial: 11!1!⋅4!⋅4!⋅2!=39,916,8001152=34,650\frac{11!}{1! \cdot 4! \cdot 4! \cdot 2!} = \frac{39{,}916{,}800}{1152} = 34{,}650.

Why it happens: the large groups catch the eye, and a group of two looks too small to matter. Yet a group of two halves the count.

How to check: list the letters with their counts before writing the formula, and make sure the counts add up to nn: here 1+4+4+2=111 + 4 + 4 + 2 = 11. Each count in that list must appear as a factorial in the denominator.

Dividing by r! when order matters

The places in the arrangement are different, but the count is done with the binomial coefficient (nr)\binom{n}{r}, which treats the chosen items as a group with no order.

Wrong working: gold, silver and bronze among 1010 runners: (103)=120\binom{10}{3} = 120.

Right working: the medals are different, so the order of the three winners matters: P(10,3)=10⋅9⋅8=720P(10, 3) = 10 \cdot 9 \cdot 8 = 720. This is 120⋅3!=720120 \cdot 3! = 720: each group of three winners can receive the medals in 66 orders.

Why it happens: "choose 3 of 10" sounds like a selection, and the binomial coefficient is the more familiar formula. The words gold, silver and bronze are what make the places different.

How to check: swap two of the winners and ask whether the result changes. If gold and silver swapped gives a different outcome, order matters and P(n,r)P(n, r) is the count.

Swapping the base and the exponent

In a count with repetition, the number of positions is used as the base and the number of options as the exponent.

Wrong working: a 4-digit PIN from the digits 0 to 9 is counted as 410=1,048,5764^{10} = 1{,}048{,}576.

Right working: there are 44 positions and each can hold any of 1010 digits, so the count is 10⋅10⋅10⋅10=104=10,00010 \cdot 10 \cdot 10 \cdot 10 = 10^4 = 10{,}000.

Why it happens: nrn^r is remembered as a pattern of two numbers, without the product of choices behind it.

How to check: write the count as a product of choices, one factor for each position. The number of factors is the exponent and each factor is the base. For a 4-digit PIN the codes 0000 to 9999 give exactly 10,00010{,}000.

Using n! for a round table

Seats around a round table are treated like places in a row, so the count is n!n!. A row has a first place; a round table does not, and turning the whole table gives the same seating.

Wrong working: 55 people around a round table: 5!=1205! = 120 seatings.

Right working: each seating appears 55 times among the 120120 rows, once for each person who could sit in the first place of the row. So the count is 5!5=4!=24\frac{5!}{5} = 4! = 24. Equivalently, fix one person and arrange the other 44: 4!=244! = 24.

Why it happens: the people are distinct and order matters, which is exactly the description of a full permutation. The extra condition that turns count as the same arrangement is easy to overlook.

How to check: take n=3n = 3. Three people around a table have only 22 seatings: the order clockwise is either A, B, C or A, C, B. The formula (3−1)!=2(3 - 1)! = 2 agrees, while 3!=63! = 6 does not.

Subtracting only the single fixed points

When counting derangements, the orders that return at least one hat are counted as n⋅(n−1)!n \cdot (n-1)! and subtracted once. Orders that return two or more hats are inside several of these counts, so they are subtracted more than once.

Wrong working: for 44 guests, 4!−4⋅3!=24−24=04! - 4 \cdot 3! = 24 - 24 = 0 derangements.

Right working: continue the alternating sum: 24−(41)3!+(42)2!−(43)1!+(44)0!=24−24+12−4+1=924 - \binom{4}{1} 3! + \binom{4}{2} 2! - \binom{4}{3} 1! + \binom{4}{4} 0! = 24 - 24 + 12 - 4 + 1 = 9.

Why it happens: "subtract the orders where someone gets their own hat" sounds like one subtraction, and n⋅(n−1)!n \cdot (n-1)! looks like the number of such orders. It is not: it counts the identity order 44 times, once for each guest.

How to check: the answer 00 is impossible for n≥2n \geq 2, since moving every hat one seat along is always a derangement. For small nn the small values listed above give a direct check: !3=2!3 = 2 and !4=9!4 = 9.

Permutations FAQ

What is a permutation?

+
An arrangement of items where the order counts. Listing three books on a shelf in a different sequence produces a different permutation, even though the same books are involved. This is the defining contrast with selections, where rearranging the chosen items changes nothing about the result.Read more →

What is the difference between permutations with and without repetition?

+
Without repetition each item can be used once, so the pool shrinks with every position filled and the count is a descending product. With repetition the full pool is available every time, so the count is one number raised to the power of the number of positions. A PIN allows repeats; seating people does not. Compare both on the permutation calculator.Read more →

How do you count arrangements when some items are identical?

+
Count as if every item were distinct, then divide by the factorial of each repeated group's size. The division removes the rearrangements among identical items, which produce no visibly different result. Arranging the letters of a word with repeated letters is the standard case where this correction is needed.Read more →

Why do you divide by n when counting circular permutations?

+
Because rotating the whole arrangement produces the same circular seating. Every distinct circle corresponds to n straight-line arrangements, one for each starting position, so the linear count overcounts by exactly that factor. Fixing one person in place and arranging the rest gives the same answer more directly.Read more →

What is the difference between nPr and n factorial?

+
Factorial arranges every item, while nPr arranges only r of them chosen from n. Factorial is the special case where r equals n, so all positions are filled. Reading nPr as a factorial of something is a common slip; it is a descending product that stops after r terms rather than continuing to one.Read more →

What does an exclamation mark before a number mean?

+
It is the subfactorial: !n!n counts the derangements of nn items, the orders that leave no item in its original place. Older texts write it DnD_n. The position of the mark is the whole difference, since !4=9!4 = 9 while 4!=244! = 24: of the 2424 orders of four items, only 99 move every item.Read more →

Is a combination lock really a combination?

+
No, its codes are permutations with repetition. A lock set to 4-7-2 does not open at 2-7-4, so order matters, and two dials may show the same digit. Three dials with the digits 0 to 9 therefore give 103=100010^3 = 1000 codes. A true combination of three different digits, where only the set of digits counts, would leave just (103)=120\binom{10}{3} = 120.Read more →

How accurate is Stirling's formula?

+
Very, even for small nn. Stirling's formula n!≈2πn(ne)nn! \approx \sqrt{2\pi n}\left(\frac{n}{e}\right)^n gives about 3,598,6963{,}598{,}696 for n=10n = 10, less than 1%1\% below 10!=3,628,80010! = 3{,}628{,}800. It comes out slightly low, with a relative error close to 112n\frac{1}{12n}, so the error keeps shrinking: about 1.7%1.7\% at n=5n = 5 and 0.4%0.4\% at n=20n = 20.Read more →

What is the chance that nobody gets their own hat back?

+
About 37%37\%, close to 1e\frac{1}{e}, for any group beyond a handful. The share of orders with no fixed point is !nn!\frac{!n}{n!}: 924=0.375\frac{9}{24} = 0.375 for 44 guests and 44120≈0.367\frac{44}{120} \approx 0.367 for 55, already near 1e≈0.3679\frac{1}{e} \approx 0.3679. So the chance that at least one guest gets their own hat settles near 63%63\%, almost whatever the number of guests.Read more →