MathAI Blog

Factorials 101: The Complete Beginner\'s Guide

Learn what factorials are, why they matter, and how to compute and apply them with fast patterns and worked examples.

Published August 17, 20251 min read

Factorials show up everywhere: counting arrangements, binomial coefficients, probability, calculus, and computer science. This complete guide explains the idea, the rules, the shortcuts, and the real-world uses, with clear examples you can try in MathAI GPT.

1) What is a Factorial?

For a whole number n ≥ 0, the factorial n! is the product of all positive integers up to n. Think of it as “how many ways can I arrange n distinct objects?”

  • 5! = 5 × 4 × 3 × 2 × 1 = 120
  • 1! = 1 (only one way to arrange 1 item)
  • 0! = 1 (by convention; there's exactly one way to arrange zero items: do nothing)

Recursive Definition

n! = n · (n−1)! with base case 0! = 1.

Example: 5! = 5 · 4! = 5 · 24 = 120

Why 0! = 1?

It might seem odd, but 0! = 1 makes formulas work smoothly. For instance,C(n,0) = n!/(0!·n!) = 1 correctly gives “1 way to choose 0 items.”

2) Fast Patterns and Shortcuts

  • Canceling in fractions: 7!/5! = 7 · 6 (because the 5! cancels). This saves massive computation!
  • Trailing zeros: count factors of 5 in n! (since 2s are abundant). Formula: ∑ floor(n/5^k) over k≥1.
  • Growth: n! grows incredibly fast; 10! = 3,628,800, 20! ≈ 2.4 × 10^18.

Examples (Canceling)

9!/7! = 9 · 8 = 72

8!/6! = 8 · 7 = 56

6!/6! = 1

Trailing Zeros Example: 100!

Step 1: Count factors of 5: ⌊100/5⌋ = 20

Step 2: Count factors of 25: ⌊100/25⌋ = 4

Step 3: Count factors of 125: ⌊100/125⌋ = 0

Total: 20 + 4 + 0 = 24 trailing zeros

3) Factorials in Combinatorics

Factorials are the backbone of counting problems. Here's the intuitive breakdown:

  • Permutations: ways to order n distinct items = n!. (Every item gets a unique position.)
  • Partial permutations: ways to arrange k items from n = P(n,k) = n! / (n−k)!. (Fill k positions from n choices.)
  • Combinations: ways to choose k from n (order doesn't matter) = C(n,k) = n! / (k!(n−k)!). (Divide by k! to ignore order.)

Worked Examples

Arrange 5 letters (ABCDE): 5! = 120 ways.

Think: 5 choices for 1st spot, 4 for 2nd, 3 for 3rd, etc.

Arrange 3 of 7 books on a shelf: P(7,3) = 7 · 6 · 5 = 210.

Think: 7 choices for 1st spot, 6 for 2nd, 5 for 3rd.

Choose 3 students from 10 for a committee: C(10,3) = 10!/(3!·7!) = 120.

Order doesn't matter in a committee, so divide by 3!.

Quick Decision Guide

Order matters? Use permutations P(n,k)

Order doesn't matter? Use combinations C(n,k)

Arranging all items? Use n!

4) Binomial Coefficients and Pascal's Triangle

The coefficients in (x + y)^n are C(n,k). Rows of Pascal's triangle match C(n,k) values.

  • C(n,k) = C(n−1,k−1) + C(n−1,k) (Pascal identity)
  • ∑_{k=0}^n C(n,k) = 2^n

5) Stirling's Approximation (For Large Factorials)

When n gets large, computing n! exactly becomes impractical. Stirling's formula gives an excellent approximation:

Stirling's Formula

n! ≈ √(2πn) · (n/e)^n

Example: 10! ≈ √(20π) · (10/e)^10 ≈ 3,598,696

Actual: 10! = 3,628,800 (error ≈ 0.8%)

6) Real-World Applications

  • Cryptography: Large factorials help generate secure keys (difficulty of factoring).
  • Probability: Calculating odds in card games, lottery combinations.
  • Computer Science: Algorithm analysis, particularly sorting and searching complexities.
  • Statistics: Binomial distributions, sampling without replacement.
  • Physics: Statistical mechanics, quantum state counting.

7) Common Mistakes (and Fixes)

  • Forgetting 0! = 1.
  • Cancelling incorrectly: expand just enough to cancel, then stop.
  • Mixing up P(n,k) and C(n,k): order matters for permutations, not for combinations.

7) Common Mistakes (and Fixes)

  • Forgetting 0! = 1 (causes errors in combination formulas).
  • Cancelling incorrectly: expand just enough to cancel, then stop.
  • Mixing up P(n,k) and C(n,k): order matters for permutations, not for combinations.
  • Computing large factorials directly instead of using cancellation or approximations.
  • Forgetting that factorials are only defined for non-negative integers (in basic contexts).

8) Practice (Answers Hidden)

8) Practice (Answers Hidden)

  1. Compute 7!.
  2. Simplify 10!/8!.
  3. How many ways to arrange 4 out of 9 items (order matters)?
  4. How many ways to choose 4 out of 9 items (order doesn't matter)?
  5. How many trailing zeros does 100! have?
  6. A password uses 8 distinct letters. How many possible passwords?
  7. Use Stirling's approximation to estimate 12!.
Show answers

1. 7! = 5040.

2. 10 · 9 = 90.

3. P(9,4) = 9 · 8 · 7 · 6 = 3024.

4. C(9,4) = 9!/(4!·5!) = 126.

5. Trailing zeros: ⌊100/5⌋ + ⌊100/25⌋ = 20 + 4 = 24.

6. P(26,8) = 26!/18! ≈ 6.27 × 10^10 (assuming English alphabet).

7. 12! ≈ √(24π) · (12/e)^12 ≈ 475,687,000 (actual: 479,001,600).

Programming Note

Computing Factorials in Code

Iterative: fact = 1; for i = 1 to n: fact *= i

Recursive: factorial(n) = n * factorial(n-1), base: factorial(0) = 1

Warning: Factorials overflow quickly! Use big integer libraries for large n.

Next Step

Open the MathAI GPT and paste two factorial problems you want to master. Ask for one step‑by‑step solution, one alternative method, and a mini‑drill to cement it.