Factorial Calculator
Calculate the factorial of an integer.
What is a Factorial?
The factorial of a non-negative integer n, written as n!, is the product of all positive integers from 1 to n. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. Factorials count the number of ways to arrange n distinct objects in order — a fundamental concept in combinatorics, probability, and statistics.
Factorials grow extraordinarily fast. While 5! = 120, 10! = 3,628,800, and 20! = 2,432,902,008,176,640,000 (over 2 quintillion). This explosive growth explains why brute-force solutions to traveling salesman and similar optimization problems become impossible beyond modest input sizes.
By definition, 0! = 1 (the empty product). Factorials are undefined for negative integers. For non-integer values, the gamma function Γ(n) extends the factorial concept: n! = Γ(n+1).
Formulas Explained
Recursive definition:
n! = n × (n-1)! for n ≥ 1
0! = 1 (base case)
Explicit formula:
n! = n × (n-1) × (n-2) × ... × 3 × 2 × 1
Stirling's approximation (for large n):
n! ≈ √(2πn) × (n/e)^n
This approximation becomes increasingly accurate for large n and is essential in statistical mechanics and information theory.
Key properties:
- n! = n × (n-1)! — recursive relationship
- n! = n × (n-1) × (n-2)! — extended recursion
- (n+1)! = (n+1) × n! — forward relationship
- n! grows faster than any exponential a^n
Step-by-Step Guide
- Enter your number (n): Input any non-negative integer (0, 1, 2, 3, ...). Example: 7
- Click calculate: The calculator computes n! using efficient algorithms
- Read your result: For 7!, result = 5,040
- View breakdown: See the multiplication: 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1
- Apply: Use in permutations, combinations, probability, or series expansions
Real Examples with Calculations
Example 1: Arranging books on a shelf
How many ways to arrange 6 different books?
Answer: 6! = 6 × 5 × 4 × 3 × 2 × 1 = 720 ways
Application: Library displays, retail product placement, task scheduling.
Example 2: Poker hand probabilities
Total 5-card hands from 52-card deck:
C(52,5) = 52! / (5! × 47!) = 2,598,960
Probability of royal flush: 4 / 2,598,960 = 1 in 649,740
Application: Game theory, gambling odds, risk assessment.
Example 3: Seating arrangements at a round table
How many ways to seat 8 people at a round table?
For circular permutations: (n-1)! = 7! = 5,040
(Note: rotations are considered identical, so we fix one person)
Application: Event planning, conference seating, tournament brackets.
Example 4: Taylor series expansion (calculus)
e^x = 1 + x + x²/2! + x³/3! + x⁴/4! + ...
For x = 1: e ≈ 1 + 1 + 1/2 + 1/6 + 1/24 + 1/120 + ...
e ≈ 1 + 1 + 0.5 + 0.167 + 0.042 + 0.008 = 2.717 (approaching 2.718)
Application: Numerical methods, physics simulations, engineering calculations.
Example 5: Password combinations
How many 8-character passwords using 26 lowercase letters with no repeats?
P(26,8) = 26! / (26-8)! = 26! / 18!
= 26 × 25 × 24 × 23 × 22 × 21 × 20 × 19 = 62,990,928,000
Application: Cybersecurity, encryption key space, brute-force attack resistance.
4 Common Mistakes
- Assuming 0! = 0: By definition, 0! = 1, not 0. This ensures formulas like C(n,0) = 1 (one way to choose nothing) work correctly. The empty product equals 1, just like empty sum equals 0.
- Trying to compute factorials of negative numbers: (-3)! is undefined. Factorials only exist for non-negative integers. The gamma function extends to non-integers but still has poles at negative integers.
- Confusing n! with n^n: 5! = 120, but 5^5 = 3,125. Factorial multiplies decreasing integers; exponentiation multiplies the same number repeatedly. They grow at very different rates.
- Overflow errors in programming: 21! exceeds 64-bit integer range. In code, use arbitrary-precision libraries (Python handles this automatically) or work with ln(n!) to avoid overflow in intermediate calculations.
4 Pro Tips
- Use logarithms for large factorials: Instead of computing n! directly, compute ln(n!) = ln(1) + ln(2) + ... + ln(n). This avoids overflow and lets you work with ratios: ln(n!/k!) = ln(n!) - ln(k!).
- Cancel factorials in combinations: C(52,5) = 52!/(5!×47!) simplifies to (52×51×50×49×48)/(5×4×3×2×1) = 2,598,960. Cancel the largest factorial before multiplying.
- Memorize small factorials: 0!=1, 1!=1, 2!=2, 3!=6, 4!=24, 5!=120, 6!=720, 7!=5,040, 8!=40,320, 9!=362,880, 10!=3,628,800. These appear constantly in probability problems.
- Apply Stirling's approximation for estimation: For n ≥ 10, n! ≈ √(2πn) × (n/e)^n gives within 1% accuracy. Useful for quick estimates: 50! ≈ √(100π) × (50/2.718)^50 ≈ 3 × 10^64.
FAQs
Zero factorial equals 1 by convention that makes formulas work. The empty product (multiplying zero numbers) equals 1, just as the empty sum equals 0. This ensures C(n,0) = n!/(0!×n!) = 1, meaning "one way to choose nothing."
The gamma function Γ(n) extends factorials to non-integers and complex numbers. For positive integers, Γ(n) = (n-1)!. So Γ(5) = 4! = 24. The gamma function enables factorials of fractions like (1/2)! = √π/2 ≈ 0.886.
This calculator handles factorials up to n = 170 (the limit of IEEE 754 double-precision floating point). 171! exceeds 10^308, causing overflow. For larger values, use arbitrary-precision tools or work with logarithms.
Factorials appear in: probability (card games, lottery odds), statistics (binomial distributions), computer science (algorithm complexity analysis), physics (quantum states, entropy), and operations research (scheduling, routing problems).
Related Calculators
Explore our mathematics calculators: Permutations Calculator, Combinations Calculator, Standard Deviation Calculator, Median Calculator, Percentage Calculator.