Factorial Calculator

Calculate n! with Detailed Steps

Factorial (n!)

Enter a non-negative integer (0-170)

Permutation & Combination

Quick Facts

  • 0! = 1 (by definition)
  • 1! = 1
  • n! grows very rapidly
  • 10! = 3,628,800

About Factorial Calculator

A factorial calculator is a mathematical tool that computes the factorial of a non-negative integer n, denoted as n!. The factorial of a number is the product of all positive integers less than or equal to that number. This calculator also computes permutations (nPr) and combinations (nCr), which are fundamental concepts in combinatorics, probability theory, and statistics. All calculations support large numbers using BigInt for precision.

What is a Factorial?

A factorial is defined as the product of all positive integers from 1 to n. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. By convention, 0! is defined as 1. Factorials grow extremely rapidly - even 10! equals 3,628,800, and 20! is already over 2 quintillion! This rapid growth makes factorials useful for counting problems where the number of possibilities increases multiplicatively.

Key Formulas

Factorial Formula

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

Special case: 0! = 1 (by definition)

Permutation Formula (nPr)

nPr = n! / (n-r)!

Number of ways to arrange r items from n items where order matters. For example, 5P3 = 5!/(5-3)! = 60.

Combination Formula (nCr)

nCr = n! / (r! × (n-r)!)

Number of ways to choose r items from n items where order doesn't matter. For example, 5C3 = 5!/(3!×2!) = 10.

Practical Applications

  • Combinatorics: Counting arrangements, permutations, and combinations in discrete mathematics. Used to solve problems like "How many ways can you arrange 5 books on a shelf?" or "How many different committees of 3 people can be formed from 10 people?"
  • Probability Theory: Calculating probabilities in card games, lottery odds, and statistical sampling. For example, the probability of getting a specific poker hand uses combinations.
  • Algebra: Binomial theorem expansions, Taylor series, and Maclaurin series use factorials in their coefficients. The expansion of (a+b)ⁿ uses nCr coefficients.
  • Computer Science: Algorithm analysis, particularly for sorting algorithms and recursive functions. Factorial time complexity O(n!) represents the worst-case scenario for brute-force solutions.
  • Cryptography: Key generation and encryption algorithms often use permutations and combinations to create secure cryptographic systems.
  • Game Theory: Analyzing possible game states, move sequences, and strategic options in games like chess, poker, and other strategy games.
  • Statistics: Sampling methods, experimental design, and hypothesis testing use factorials to calculate the number of possible samples or arrangements.

Step-by-Step Calculation Examples

Example 1: Calculate 6!

Step 1: Write out the multiplication: 6! = 6 × 5 × 4 × 3 × 2 × 1

Step 2: Calculate from left to right:

  • 6 × 5 = 30
  • 30 × 4 = 120
  • 120 × 3 = 360
  • 360 × 2 = 720
  • 720 × 1 = 720

Result: 6! = 720

Example 2: Calculate 8P3 (Permutation)

Formula: 8P3 = 8! / (8-3)! = 8! / 5!

Step 1: Simplify: 8P3 = 8 × 7 × 6 (cancel out 5!)

Step 2: Calculate: 8 × 7 × 6 = 336

Result: 8P3 = 336 ways to arrange 3 items from 8

Example 3: Calculate 10C4 (Combination)

Formula: 10C4 = 10! / (4! × 6!)

Step 1: Simplify: 10C4 = (10 × 9 × 8 × 7) / (4 × 3 × 2 × 1)

Step 2: Calculate numerator: 10 × 9 × 8 × 7 = 5,040

Step 3: Calculate denominator: 4! = 24

Step 4: Divide: 5,040 / 24 = 210

Result: 10C4 = 210 ways to choose 4 items from 10

Common Factorial Values

nn!DigitsTrailing Zeros
0110
512031
103,628,80072
151,307,674,368,000133
202,432,902,008,176,640,000194
2515,511,210,043,330,985,984,000,000266
503.04×10⁶⁴6512

Permutations vs Combinations

Understanding the difference between permutations and combinations is crucial for solving counting problems correctly:

Permutations (nPr) - Order Matters

Use permutations when the order of selection matters. For example, the arrangements "ABC", "ACB", and "BAC" are different permutations. Real-world examples include:

  • Arranging books on a shelf
  • Determining race finishing positions
  • Creating passwords or PIN codes
  • Seating arrangements at a table

Combinations (nCr) - Order Doesn't Matter

Use combinations when the order doesn't matter. For example, choosing (A, B, C) is the same as choosing (C, A, B). Real-world examples include:

  • Selecting committee members
  • Choosing lottery numbers
  • Picking pizza toppings
  • Forming teams from a group

Properties of Factorials

  • Rapid Growth: Factorials grow faster than exponential functions. While 2ⁿ grows quickly, n! grows even faster. This is why factorial time complexity O(n!) is considered impractical for large n.
  • Trailing Zeros: The number of trailing zeros in n! equals the number of times 10 divides n!, which is determined by the number of pairs of factors 2 and 5. Since there are always more 2s than 5s, count the 5s.
  • Divisibility: n! is divisible by all integers from 1 to n. This makes factorials useful in number theory and modular arithmetic.
  • Recursive Definition: n! = n × (n-1)! with base case 0! = 1. This recursive property is fundamental in computer science and algorithm design.
  • Stirling's Approximation: For large n, n! ≈ √(2πn) × (n/e)ⁿ. This approximation is useful when exact values aren't needed.

Tips for Using This Calculator

  • Enter any non-negative integer from 0 to 170 for factorial calculations
  • Values above 170 cause overflow in standard floating-point arithmetic, but our calculator uses BigInt for precision
  • For permutations and combinations, ensure r ≤ n (you can't choose more items than available)
  • The calculator shows step-by-step solutions for better understanding
  • Properties like digit count and trailing zeros help analyze the result
  • Use the reset button to clear all inputs and start fresh
  • Results are formatted with commas for easier reading of large numbers

Frequently Asked Questions

Why is 0! equal to 1?

By definition, 0! = 1. This convention makes many mathematical formulas work correctly. For example, the binomial coefficient nC0 = n!/(0!×n!) = 1, which correctly represents that there's exactly one way to choose zero items. Additionally, the recursive formula n! = n × (n-1)! requires 0! = 1 to work for n = 1.

What's the largest factorial I can calculate?

This calculator supports factorials up to 170! due to JavaScript's number precision limits. Beyond 170!, the result exceeds the maximum representable number even with BigInt. However, 170! is already an astronomically large number with 307 digits, sufficient for virtually all practical applications.

How do I calculate factorials of negative numbers?

Factorials are only defined for non-negative integers (0, 1, 2, 3, ...). Negative factorials don't exist in standard mathematics. However, the gamma function Γ(n) = (n-1)! extends the factorial concept to real and complex numbers.

When should I use permutations vs combinations?

Use permutations (nPr) when order matters - like arranging items or determining rankings. Use combinations (nCr) when order doesn't matter - like selecting team members or choosing items. Remember: nPr ≥ nCr always, because permutations count more arrangements.

Why do factorials grow so fast?

Each factorial multiplies by an increasing number: n! = n × (n-1) × (n-2) × ... × 1. This multiplicative growth is much faster than additive or exponential growth. For example, 10! = 3,628,800 but 2¹⁰ = 1,024. This rapid growth makes factorial time algorithms impractical for large inputs.

How are trailing zeros calculated?

Trailing zeros come from factors of 10, which require pairs of 2 and 5. Since factorials have more factors of 2 than 5, we count factors of 5. The formula is: floor(n/5) + floor(n/25) + floor(n/125) + ... For example, 25! has 6 trailing zeros because 25/5 = 5 and 25/25 = 1, so 5 + 1 = 6.

Advanced Topics

  • Gamma Function: Γ(n) = (n-1)! extends factorials to real and complex numbers. It's defined as Γ(n) = ∫₀^∞ t^(n-1)e^(-t)dt and satisfies Γ(n+1) = nΓ(n).
  • Double Factorial: n!! means the product of all integers from 1 to n that have the same parity. For example, 7!! = 7×5×3×1 = 105.
  • Subfactorial: !n (derangements) counts permutations where no element appears in its original position. Formula: !n = n! × Σ((-1)^k/k!) for k=0 to n.
  • Falling Factorial: (n)ₖ = n(n-1)(n-2)...(n-k+1) = n!/(n-k)! = nPk. Used in combinatorics and finite differences.
  • Rising Factorial: n^(k) = n(n+1)(n+2)...(n+k-1). Used in hypergeometric functions and special function theory.

Related Mathematical Concepts

  • Binomial Coefficients: The coefficients in the expansion of (a+b)ⁿ are combinations: nCk appears as the coefficient of a^(n-k)b^k.
  • Multinomial Coefficients: Generalization of binomial coefficients for more than two terms: n!/(k₁!k₂!...kₘ!) where k₁+k₂+...+kₘ = n.
  • Catalan Numbers: Cₙ = (2n)!/(n!(n+1)!) counts various combinatorial structures like balanced parentheses and binary trees.
  • Stirling Numbers: Count ways to partition n objects into k non-empty subsets (second kind) or arrange n objects into k cycles (first kind).