Factorial Calculator
Factorial Calculator. Free online calculator with formula, examples and step-by-step guide.
What is a Factorial Calculator?
A factorial calculator computes n! (n factorial) — the product of all positive integers from 1 to n. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. Factorials count permutations (arrangements) of objects: 5 books can be arranged in 5! = 120 different orders. Factorials explode rapidly: 10! = 3,628,800, 20! = 2.4 quintillion, 52! (shuffling a deck of cards) = 8.07 × 10⁶⁷ — more than atoms in the observable universe. This calculator handles small factorials (6! = 720) for homework, medium factorials (50!) for statistics, and large factorials (up to 170! in scientific notation) for advanced combinatorics. Use factorials for: calculating lottery odds (choose 6 from 49), arranging seating charts, analyzing sorting algorithms, computing probabilities (poker hands), and evaluating Taylor series in calculus.
Formulas Explained with Actual Calculations
Basic Factorial Formula: n! = n × (n-1) × (n-2) × ... × 3 × 2 × 1. Example: 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5,040. Step by step: 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 6! = 720, 7! = 5,040. Each factorial is the previous one multiplied by n: n! = n × (n-1)!. This recursive definition enables efficient computation.
Zero Factorial: 0! = 1 by definition. Why? The empty product (multiplying no numbers) equals 1 (multiplicative identity). Combinatorially: there's exactly 1 way to arrange 0 objects (do nothing). In formulas: C(n,0) = n!/(0!×n!) = 1 (choosing nothing from n items has 1 outcome — choose none). Without 0! = 1, countless formulas break.
Stirling's Approximation (Large Factorials): For n ≥ 10, n! ≈ √(2πn) × (n/e)ⁿ. Example: 20! exact = 2,432,902,008,176,640,000. Stirling: √(40π) × (20/2.718)²⁰ = 11.21 × 7.36²⁰ = 11.21 × 2.16×10¹⁷ = 2.42×10¹⁸ — within 0.5% of exact value. For n = 100: Stirling gives 9.33×10¹⁵⁷ (actual: 9.33×10¹⁵⁷). Essential for statistical mechanics and large-scale combinatorics.
Double Factorial: n!! = product of integers with same parity as n. Odd: 9!! = 9 × 7 × 5 × 3 × 1 = 945. Even: 10!! = 10 × 8 × 6 × 4 × 2 = 3,840. Appears in combinatorics (perfect matchings) and physics (Legendre polynomials). Note: 0!! = 1, (-1)!! = 1 by convention.
Multifactorial: n!⁽ᵏ⁾ = n × (n-k) × (n-2k) × ... until reaching 1 or 2. Example: 10!⁽³⁾ (triple factorial) = 10 × 7 × 4 × 1 = 280. Generalizes double factorial to step-k products.
6 Step-by-Step Instructions
- Identify if you need a standard factorial or variation: Standard n! for permutations and combinations. Double factorial n!! for specific combinatorial problems (matching pairs, binary trees). Multifactorial for specialized applications. Most users need standard factorial.
- Enter n (must be non-negative integer for standard factorial): For 6!, enter 6. For 0!, enter 0 (result: 1). Negative factorials are undefined (gamma function extends to non-integers, but that's advanced). Non-integers like 3.5! use the gamma function: Γ(4.5) ≈ 11.63 — this calculator handles integers only.
- Calculate using iterative multiplication or the calculator: Small n: multiply manually. 6! = 6×5×4×3×2×1 = 720. Medium n: use calculator. 15! = 1,307,674,368,000. Large n: scientific notation. 50! ≈ 3.04×10⁶⁴. For n > 170, most calculators overflow — this calculator uses arbitrary precision arithmetic.
- For combinations and permutations, apply factorial formulas: Permutations (order matters): P(n,r) = n!/(n-r)!. Example: Arrange 3 books from 5: P(5,3) = 5!/2! = 120/2 = 60. Combinations (order doesn't matter): C(n,r) = n!/(r!×(n-r)!). Example: Choose 3 from 5: C(5,3) = 5!/(3!×2!) = 120/(6×2) = 10. Lottery: C(49,6) = 13,983,816 combinations — 1 in 14 million odds.
- Verify magnitude makes sense: Factorials grow super-exponentially. Quick reference: 5! = 120 (3 digits), 10! = 3.6 million (7 digits), 15! = 1.3 quadrillion (13 digits), 20! = 2.4 quintillion (19 digits). If your 10! shows as 362,880 (6 digits), you miscounted — should be 3,628,800 (7 digits). Use digit estimate: digits in n! ≈ n×log₁₀(n/e) + log₁₀(√(2πn)). For n=10: 10×0.633 + 0.399 = 6.73 → 7 digits ✓.
- Apply to your specific problem: Arranging 8 people in a line: 8! = 40,320 arrangements. Seating 6 at round table (rotation doesn't matter): (6-1)! = 5! = 120. Shuffling deck: 52! arrangements. Password with 10 unique characters: 10! = 3.6 million permutations. Race with 12 runners, top 3 podium: P(12,3) = 12!/9! = 12×11×10 = 1,320 outcomes. Select 5-card poker hand: C(52,5) = 2,598,960 hands.
5 Real-World Examples with Specific Numbers
Example 1 — Lottery Odds Calculation: A lottery draws 6 numbers from 49 without replacement. How many possible combinations? C(49,6) = 49!/(6!×43!) = (49×48×47×46×45×44)/(6×5×4×3×2×1). Calculate numerator: 49×48 = 2,352, ×47 = 110,544, ×46 = 5,085,024, ×45 = 228,826,080, ×44 = 10,068,347,520. Denominator: 6! = 720. Result: 10,068,347,520 / 720 = 13,983,816 combinations. Odds of winning: 1 in 13,983,816. If you buy 10 tickets weekly: 10/13,983,816 = 1 in 1,398,382 per week. Expected time to win: 13,983,816 / 520 = 26,892 years. This explains why lotteries are "tax on people who can't calculate factorials."
Example 2 — Seating Arrangement for Wedding: Wedding reception: 8 tables, 10 guests each. How many seating arrangements? For one table: 10! = 3,628,800 arrangements. But rotations are equivalent (circular permutation): (10-1)! = 9! = 362,880 per table. For 8 tables: (9!)⁸ = (362,880)⁸ = 2.8×10⁴⁴ arrangements — more than atoms in Earth. Practical approach: assign guests to tables first (C(80,10) × C(70,10) × ... = 80!/(10!)⁸ ways), then arrange within tables. Total: 80!/(10!)⁸ × (9!)⁸ = 80!/10⁸ arrangements. Event planners use heuristic algorithms (not brute force) to optimize seating — factorials make exhaustive search impossible.
Example 3 — Poker Probability (Full House): A full house has 3 cards of one rank and 2 of another. How many full house hands? Step 1: Choose rank for triple: C(13,1) = 13. Step 2: Choose 3 suits from 4: C(4,3) = 4. Step 3: Choose rank for pair (different): C(12,1) = 12. Step 4: Choose 2 suits from 4: C(4,2) = 6. Total: 13 × 4 × 12 × 6 = 3,744 full house hands. Total 5-card hands: C(52,5) = 2,598,960. Probability: 3,744 / 2,598,960 = 0.00144 = 0.144% (1 in 694). Compare to royal flush: 4 / 2,598,960 = 0.000154% (1 in 649,740). Full house is 694× more likely than royal flush — factorials quantify these odds precisely.
Example 4 — Algorithm Complexity Analysis: Traveling Salesman Problem (TSP): find shortest route visiting n cities once. Brute-force approach: try all permutations = n! routes. For n = 10: 10! = 3,628,800 routes — feasible on modern computers (milliseconds). For n = 15: 15! = 1.3 trillion routes — hours to days. For n = 20: 20! = 2.4×10¹⁸ routes — thousands of years on supercomputers. For n = 60: 60! ≈ 10⁸² — longer than universe's age. This factorial explosion proves brute-force TSP is intractable. Dynamic programming reduces to O(n²×2ⁿ): for n=20, that's 400×1,048,576 = 419 million operations (seconds). For n=60: 3,600×10¹⁸ — still infeasible. Factorial complexity defines the boundary of computability.
Example 5 — Taylor Series Approximation (Engineering): e^x = Σ(xⁿ/n!) = 1 + x + x²/2! + x³/3! + ... Engineers use truncated series for approximations. Calculate e² (actual: 7.389). Truncate at n=6: 1 + 2 + 4/2 + 8/6 + 16/24 + 32/120 + 64/720 = 1 + 2 + 2 + 1.333 + 0.667 + 0.267 + 0.089 = 7.356 — within 0.4% of actual. At n=10: add 128/5040 + 256/40320 + 512/362880 + 1024/3628800 = 0.025 + 0.006 + 0.0014 + 0.0003 = 7.3887 — within 0.003%. Factorials in denominators make series converge rapidly. Calculators use similar series (with optimizations) to compute transcendental functions. Without factorials, numerical methods would require far more terms for accuracy.
4 Common Mistakes
Mistake 1: Confusing Permutations with Combinations
Permutations count arrangements where ORDER matters (ABC ≠ BAC). Combinations count selections where order doesn't matter (ABC = BAC). Formula: P(n,r) = n!/(n-r)! vs. C(n,r) = n!/(r!×(n-r)!). Example: Choosing 3 from 5. Permutations: 5!/2! = 60. Combinations: 5!/(3!×2!) = 10. Difference is 6× — exactly 3! (the number of ways to arrange 3 items). Trap: "How many ways to pick a committee of 3 from 10?" Combination (C(10,3) = 120), not permutation. "How many ways to award gold/silver/bronze medals to 10 runners?" Permutation (P(10,3) = 720). The question "does order matter?" determines which formula.
Mistake 2: Misapplying the Recursive Formula
n! = n × (n-1)! is powerful but dangerous if misused. Computing 5! as 5 × 4! requires knowing 4! = 24. But people sometimes chain incorrectly: 5! = 5 × 4 × 3! = 5 × 4 × 6 = 120 ✓ (correct). But 5! = 5 × 4 × 3 × 2! = 5 × 4 × 3 × 2 = 120 ✓ (also correct). The error: forgetting the base case. Infinite recursion: 5! = 5 × 4!, 4! = 4 × 3!, 3! = 3 × 2!, 2! = 2 × 1!, 1! = 1 × 0!, 0! = 0 × ... undefined! Stop at 0! = 1 or 1! = 1. Base cases are essential. In programming, factorial without base case causes stack overflow.
Mistake 3: Overflow Errors with Large Factorials
Factorials exceed computer integer limits quickly. 12! = 479,001,600 fits in 32-bit integer (max 2.1 billion). 13! = 6,227,020,800 exceeds 32-bit — needs 64-bit integer (max 9.2×10¹⁸). 20! = 2.4×10¹⁸ fits in 64-bit. 21! = 5.1×10¹⁹ overflows 64-bit. Solution: use arbitrary-precision libraries (Python handles big integers automatically) or scientific notation. 100! = 9.33×10¹⁵⁷ — can't represent as integer in most languages, but fine as float. For exact large factorials, use specialized libraries. Trap: intermediate overflow in C(n,r) = n!/(r!×(n-r)!). Computing 52! directly overflows, but C(52,6) fits in integer if you cancel factorials first: 52!/(6!×46!) = (52×51×50×49×48×47)/(6×5×4×3×2×1) = 20,358,520 — no overflow.
Mistake 4: Forgetting That Factorials Are Only for Non-Negative Integers
Standard factorial n! requires n ≥ 0 and n integer. Negative factorials (-5!) are undefined. Fractional factorials (3.5!) use the gamma function Γ(n+1), which extends factorials to real/complex numbers. Γ(4.5) = 3.5! ≈ 11.63. But this calculator and most basic tools handle integers only. Trap: "Arrange -3 books" or "Choose 2.5 from 7" — nonsense questions that sometimes appear from typos. Another trap: 0! = 1 surprises people who expect 0. Remember: empty product = 1, empty sum = 0. Zero objects have exactly 1 arrangement (the empty arrangement).
4-5 Pro Tips
Tip 1: Memorize Small Factorials for Quick Recognition
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. Seeing 720, recognize 6!. Seeing 40,320, recognize 8!. This speeds calculation and catches errors. If your permutation formula gives 5,000 for P(7,3), you know it's wrong — should be 7×6×5 = 210. For combinations: C(8,4) = 70, C(10,5) = 252, C(12,6) = 924. Flashcard these values. In probability, recognizing 1/120 = 1/5! or 1/720 = 1/6! reveals patterns in solutions.
Tip 2: Cancel Factorials Before Computing Combinations
C(n,r) = n!/(r!×(n-r)!) simplifies dramatically. C(52,5) = 52!/(5!×47!) = (52×51×50×49×48)/(5×4×3×2×1). Don't compute 52! then divide — compute the product of r descending terms from n, divide by r!. C(52,5) = (52×51×50×49×48)/120 = 311,875,200/120 = 2,598,960. For C(100,3): (100×99×98)/6 = 970,200/6 = 161,700. This technique avoids overflow and is faster. General formula: C(n,r) = (n/r) × C(n-1,r-1) — recursive computation. For programming: compute iteratively, not with factorials.
Tip 3: Use Logarithms for Extremely Large Factorials
For n > 170, n! overflows standard floating-point. Compute ln(n!) instead: ln(n!) = ln(1) + ln(2) + ... + ln(n). For n = 1000: sum 1000 logarithms. Or use Stirling: ln(n!) ≈ n×ln(n) - n + 0.5×ln(2πn). For n = 1000: 1000×ln(1000) - 1000 + 0.5×ln(2000π) = 6907.8 - 1000 + 4.6 = 5912.4. So 1000! ≈ e⁵⁹¹²·⁴ ≈ 10²⁵⁶⁸ — a number with 2,568 digits. Logarithmic factorial appears in statistical mechanics (entropy calculations) and information theory (counting microstates).
Tip 4: Recognize Factorial Growth Patterns
Factorials grow faster than exponential. Compare 2ⁿ vs. n!: n=10: 2¹⁰=1,024, 10!=3.6M (3,500× larger). n=20: 2²⁰=1M, 20!=2.4×10¹⁸ (2.4 trillion× larger). n=50: 2⁵⁰=10¹⁵, 50!=3×10⁶⁴ (10⁴⁹× larger — more than atoms in universe). This explains why brute-force algorithms with factorial complexity fail for modest inputs. Sorting: O(n log n) vs. O(n!) — merge sort handles billions, bogosort (random shuffling) fails beyond 20 items. Understand growth rates to choose feasible algorithms.
Tip 5: Apply Factorial Identities for Simplification
Key identities: (1) n! = n × (n-1)! — recursive definition. (2) (2n)!/(n!)² = C(2n,n) — central binomial coefficient. (3) n! × C(n,r) = P(n,r) — permutations from combinations. (4) (n+1)! - n! = n! × n — difference of consecutive factorials. Example: simplify (n+2)!/n! = (n+2)(n+1)n!/n! = (n+2)(n+1). Example: prove C(n,k) = C(n,n-k). C(n,k) = n!/(k!(n-k)!) = n!/((n-k)!k!) = C(n,n-k). These identities solve combinatorial proofs and simplify algebraic expressions with factorials.
4 Frequently Asked Questions
Why is 0! equal to 1 and not 0?
Three justifications: (1) Empty product convention: multiplying zero numbers gives the multiplicative identity (1), just as adding zero numbers gives the additive identity (0). (2) Combinatorial: there's exactly 1 way to arrange 0 objects — the empty arrangement. (3) Formula consistency: C(n,n) = n!/(n!×0!) should equal 1 (choosing all n from n). If 0! = 0, this is undefined. If 0! = 1, we get 1. Taylor series: e^x = Σ(xⁿ/n!) requires 0! = 1 for the n=0 term (x⁰/0! = 1/1 = 1). Gamma function: Γ(1) = 0! = 1. All mathematical frameworks agree: 0! = 1 is the only consistent definition.
How do I calculate factorials for non-integer values?
Use the gamma function: Γ(z) = ∫₀^∞ t^(z-1)e^(-t) dt. For positive integers: Γ(n) = (n-1)!. For non-integers: Γ(3.5) = 2.5! ≈ 3.323. Relationship: n! = Γ(n+1). So 3.5! = Γ(4.5) ≈ 11.632. Common values: 0.5! = Γ(1.5) = √π/2 ≈ 0.886. 1.5! = 3√π/4 ≈ 1.329. Negative non-integers work too: (-0.5)! = Γ(0.5) = √π ≈ 1.772. But negative integers are undefined (poles): (-1)!, (-2)!, etc. diverge to infinity. Most calculators don't support gamma — use Wolfram Alpha or scientific computing libraries (SciPy: scipy.special.gamma()).
What's the largest factorial I can compute?
Depends on your system: 32-bit integer: max 12! = 479,001,600. 64-bit integer: max 20! = 2,432,902,008,176,640,000. 64-bit float: max ~170! ≈ 7.3×10³⁰⁶ (beyond this overflows to infinity). Arbitrary precision (Python, Mathematica): limited only by memory. Python computed 10⁶! (factorial of 1 million) — a number with 5.5 million digits, requiring ~5 MB storage. World record: factorial of 10¹² (trillion) computed in 2023, resulting in a number with ~10¹³ digits — exabytes of storage. Practical limit for most users: 1000! (2,568 digits) is computable instantly on any modern device.
How are factorials used in real life outside math class?
(1) Cryptography: RSA encryption uses factorial-like products (primorials) for key generation. (2) Quality control: binomial distributions (using factorials) model defect rates. (3) Logistics: traveling salesman variants optimize delivery routes (factorial complexity requires heuristics). (4) Genetics: calculating possible gene combinations from parent alleles. (5) Network routing: counting paths through networks. (6) Queueing theory: call center staffing uses factorial-based Poisson distributions. (7) Computer science: analyzing sorting/searching algorithm complexity. (8) Finance: option pricing models use factorial terms in series expansions. Factorials are the hidden math behind "how many ways" questions in every quantitative field.
Related Calculators
See also: Permutation Calculator, Combination Calculator, Probability Calculator, Binomial Coefficient Calculator, Gamma Function Calculator