Factorial Calculator

Range: 0 to 170 (JavaScript limit)

📊 Result

5!
=
120
📏 Digits
3
🔟 Trailing Zeros
1
🔢 Scientific
1.2e+2

📝 Step-by-Step Calculation:

🎨 Visual Multiplication Tree

🎯 Permutations & Combinations

🔄 Permutations P(n,r)

Formula: P(n,r) = n!/(n-r)!
60
5!/(5-3)! = 60

💡 Order matters: ABC ≠ BAC

🎲 Combinations C(n,r)

Formula: C(n,r) = n!/(r!(n-r)!)
10
5!/(3!×2!) = 10

💡 Order doesn't matter: ABC = BAC

📋 Factorial Reference Table

n n! Digits Real-World Example

💡 Interesting Facts

🃏 Shuffling Cards

52! ≈ 8.07 × 10⁶⁷ possible arrangements. If every person on Earth shuffled one deck per second since the Big Bang, we'd barely scratch the surface!

🎭 Theater Seating

10 people can be seated in 10! = 3,628,800 different ways. Managing theater logistics becomes exponentially complex!

📊 0! = 1

By definition, 0! = 1. There's exactly one way to arrange zero objects: do nothing! This makes mathematical formulas work consistently.

🚀 Growth Rate

Factorial grows faster than exponential! While 2ⁿ doubles, n! multiplies by increasing values. 100! has 158 digits!

Factorial Calculator - Calculate n! with Steps

🔢 Calculate factorial (n!) for any number from 0 to 170. See step-by-step breakdown, permutations, combinations, and real-world applications.

What is a Factorial?

The factorial of a non-negative integer n, denoted as n!, is the product of all positive integers less than or equal to n. It represents the number of ways to arrange n distinct objects.

Factorial Formula

n! = n × (n-1) × (n-2) × ... × 3 × 2 × 1

  • 0! = 1 (by definition)
  • 1! = 1
  • n! = n × (n-1)! (recursive definition)

Factorial Examples

  • 5! = 5 × 4 × 3 × 2 × 1 = 120
  • 10! = 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 3,628,800
  • 0! = 1 (special case)
  • 20! = 2,432,902,008,176,640,000

Why 0! = 1?

There's exactly one way to arrange zero objects: the empty arrangement. This definition ensures that mathematical formulas (especially in combinatorics) work correctly. It's also consistent with the recursive formula: n! = n × (n-1)!, so 1! = 1 × 0! means 0! must equal 1.

Permutations

P(n,r) = n!/(n-r)!

Number of ways to arrange r objects from n distinct objects where order matters.

  • Example: P(5,3) = 5!/(5-3)! = 120/2 = 60
  • Use case: Podium positions in a race (1st, 2nd, 3rd)

Combinations

C(n,r) = n!/(r!(n-r)!)

Number of ways to choose r objects from n distinct objects where order doesn't matter.

  • Example: C(5,3) = 5!/(3!×2!) = 120/(6×2) = 10
  • Use case: Lottery numbers, committee selection

Trailing Zeros in n!

Trailing zeros are created by factors of 10 = 2 × 5. Since there are always more factors of 2 than 5, we only need to count factors of 5:

Zeros = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ...

  • 10! has 2 trailing zeros (10, 5)
  • 25! has 6 trailing zeros (5, 10, 15, 20, 25×2)
  • 100! has 24 trailing zeros

Real-World Applications

  • Cryptography: Number of possible encryption keys
  • Scheduling: Ways to arrange appointments, tasks, events
  • Genetics: Possible DNA/protein sequences
  • Probability: Calculating odds in games, lotteries
  • Computer Science: Algorithm complexity analysis
  • Manufacturing: Production line arrangements
  • Logistics: Route optimization problems

Famous Factorial Values

  • 52! ≈ 8.07 × 10⁶⁷ (card shuffling combinations)
  • 70! ≈ 1.2 × 10¹⁰⁰ (exceeds atoms in universe ≈ 10⁸⁰)
  • 100! ≈ 9.3 × 10¹⁵⁷ (158 digits!)
  • 170! ≈ 7.3 × 10³⁰⁶ (JavaScript maximum)

Stirling's Approximation

For large n, calculating exact factorials is impractical. Stirling's approximation provides:

n! ≈ √(2πn) × (n/e)ⁿ

This approximation becomes more accurate as n increases. For n = 10, error is < 1%.

Factorial Growth Rate

Factorial grows much faster than exponential or polynomial functions:

  • Polynomial: n² = 100 for n=10
  • Exponential: 2ⁿ = 1,024 for n=10
  • Factorial: n! = 3,628,800 for n=10

Double Factorial

Double factorial (n!!) multiplies every other number:

  • n!! = n × (n-2) × (n-4) × ... × 2 or 1
  • 7!! = 7 × 5 × 3 × 1 = 105
  • 8!! = 8 × 6 × 4 × 2 = 384

Subfactorial (Derangements)

Subfactorial !n counts permutations where no element appears in its original position:

!n = n! × (1/0! - 1/1! + 1/2! - 1/3! + ... + (-1)ⁿ/n!)

Example: !3 = 2 (arrangements of ABC where no letter is in original position: BCA, CAB)

Programming Implementation

Iterative approach:

function factorial(n) {
    let result = 1;
    for (let i = 2; i <= n; i++) {
        result *= i;
    }
    return result;
}
            

Recursive approach:

function factorial(n) {
    if (n === 0 || n === 1) return 1;
    return n * factorial(n - 1);
}
            

💡 Pro Tip: When calculating permutations or combinations, cancel common factors before computing to avoid overflow. For C(100,2) = 100!/(2!×98!), calculate as (100×99)/2 = 4,950 instead of computing the huge factorials separately!

Comments (0)

Share your thoughts — please be polite and stay on topic.

No comments yet. Leave a comment — share your opinion!

To leave a comment, please log in.

Log in to comment