You are setting a four digit PIN for a new phone. The PIN 1234 and the PIN 4321 use the same digits, but they are different PINs, because the order matters. How many different PINs are possible? Counting problems like this, where the order of the items matters, are what permutations are for.
Permutations are the first tool in counting, and they quietly power a lot of data work. They tell you how many ways to rank items, how many passwords an attacker must try, how many test orders a schedule allows, and how large a search space is before you design an algorithm. They are also the base for combinations and for probability.
This tutorial explains what a permutation is, the formula and the factorial behind it, worked examples with and without repeated items, how it differs from a combination, and how to check your counts in Python. You only need basic multiplication.
A permutation is an arrangement of objects in a definite order. When you choose r objects out of n, and the order matters, each different ordered arrangement is one permutation. The word to remember is order. Choosing A then B is different from choosing B then A.
Example: from the letters A, B and C, take two at a time. The permutations are AB, AC, BA, BC, CA and CB. That is 6 arrangements. Note that AB and BA are counted separately.
The permutation formula uses factorials. n factorial, written n!, is the product of all whole numbers from n down to 1.
Use a permutation when you must count ordered outcomes, such as these.
The live page uses this problem: eight cousins must be accommodated in two rooms with 3 beds each and one room with 2 beds. In how many ways can they be placed? It is solved below, after the formula.
The number of permutations of r objects chosen from n different objects is:

It is the same as multiplying r numbers, starting at n and going down. For example, 10P3 = 10 times 9 times 8 = 720. The first position has 10 choices, the second has 9 left, and the third has 8.
| Case | Formula |
|---|---|
| All n objects arranged | n! (this is nPn) |
| r out of n objects, no repeats | n! divided by (n minus r)! |
| r positions, repeats allowed | n to the power r |
| n objects where some are identical | n! divided by (p! times q! times and so on), where p, q and so on count the identical items |
| n objects around a circle | (n minus 1)! |
A club of 10 members elects a president, a vice president and a secretary. The roles are different, so order matters. The number of ways is 10P3 = 10 times 9 times 8 = 720.
Five people line up for a photo. The number of orders is 5! = 120.
| Question | Count |
|---|---|
| 4 digit PIN, digits can repeat | 10 to the power 4 = 10,000 |
| 4 digit PIN, no digit repeated | 10P4 = 10 times 9 times 8 times 7 = 5,040 |
Not allowing repeats cuts the choices by half. This is why many systems forbid PINs like 1111.
How many different arrangements are there of the letters of BOOK? There are 4 letters, but the two O’s are identical, so swapping them gives nothing new. The count is 4! divided by 2! = 24 divided by 2 = 12.
For the word LETTER, there are 6 letters with two E’s and two T’s. The count is 6! divided by (2! times 2!) = 720 divided by 4 = 180.
Eight cousins must be placed in rooms with 3, 3 and 2 beds. Treat the rooms as different. Give each cousin a room label: A for the first 3 bed room, B for the second, and C for the 2 bed room. A placement is then an arrangement of the letters AAABBBCC. This is a permutation with repeated items:
8! divided by (3! times 3! times 2!) = 40,320 divided by (6 times 6 times 2) = 40,320 divided by 72 = 560 ways.

I checked this by listing every distinct arrangement of AAABBBCC in Python, which gave 560. If the two 3 bed rooms are interchangeable, so that swapping the groups of the two rooms gives the same plan, divide by 2 and the answer is 280. The live page states no answer, so state which assumption you use.
Five people A, B, C, D and E sit in a row. In how many ways can A and B sit next to each other? Treat A and B as one block. The block and the other three people make 4 units, which can be arranged in 4! = 24 ways. Inside the block, A and B can swap, so multiply by 2. The answer is 48. A Python count of all 120 orders, keeping those with A and B side by side, also gives 48.
Six people sit around a round table. Rotating everyone one seat gives the same arrangement, so fix one person and arrange the other five. The count is (6 minus 1)! = 120, not 720.
| Feature | Permutation | Combination |
|---|---|---|
| Does order matter? | Yes | No |
| Question | How many ordered arrangements? | How many selections or groups? |
| Formula | n! divided by (n minus r)! | n! divided by (r! times (n minus r)!) |
| Example, 3 out of 10 | 720 | 120 |
| Example | President, vice president, secretary | A committee of 3 |
The link: nPr = nCr times r!. For 10 and 3, 120 times 6 = 720. Each group of 3 people can be ordered in 3! = 6 ways. A quick test: if swapping two items gives a different outcome, use a permutation. If it gives the same outcome, use a combination.
Python has permutation tools built in. I ran the code below, and the output is real.
Take care with the listing method. It creates every arrangement, so it is only practical for small cases. For 8 letters it is instant, and for 15 or more items it would run out of memory. Use the formula for large counts.
| Mistake | Fix |
|---|---|
| Using a permutation when order does not matter | Use a combination |
| Forgetting to divide for identical items | Divide by the factorial of each repeated count |
| Treating nPr as n times r | Multiply r numbers going down from n |
| Using (n minus 1)! for a straight line | That is only for circles |
| Forgetting that 0! = 1 | Remember it, so that nPn works |
| Not stating assumptions, such as rooms being identical | Say whether the groups are labelled or not |
Answers: 1) 4! = 24. 2) 8 times 7 = 56. 3) LEVEL has 5 letters, with L twice and E twice. 5! divided by (2! times 2!) = 120 divided by 4 = 30. 4) (7 minus 1)! = 720. These are my own calculations, so please recheck them before publishing.
Permutations come down to one question: does the order matter? If yes, count positions one at a time and multiply the choices, or use the formula. Work through a few small cases by hand, confirm them in Python, and the formulas will feel natural. Next, learn combinations and see how the two are linked.