Factorial Calculator — Free Online n! Calculator
Calculate factorials for any value from 0 to 1000 with exact arbitrary-precision results, full expansion, digit count, and trailing zero analysis.
| n | n! |
|---|---|
| 0 | 1 |
| 1 | 1 |
| 2 | 2 |
| 3 | 6 |
| 4 | 24 |
| 5 | 120 |
| 6 | 720 |
| 7 | 5040 |
| 8 | 40320 |
| 9 | 362880 |
| 10 | 3628800 |
10!
3,628,800
Expansion
10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 3628800Formula
n! = n × (n-1) × (n-2) × ... × 2 × 1Digits in Result
7
Trailing Zeros
2
How to Use the Factorial Calculator
- Enter a non-negative integer: Type any whole number from 0 to 1000 into the input field. The calculator only accepts non-negative integers since factorials are not defined for negative numbers or decimals (the gamma function extends to non-integers, but that is a different operation).
- View the factorial table: For values of 20 or less, a convenient reference table appears on the left showing all factorials from 0! through your entered value. The current value's row is highlighted. This is helpful for quick reference and verification.
- Read the result: The n! value is displayed prominently. For small values (n ≤ 20), the full multiplication sequence is shown (e.g., 5! = 5 × 4 × 3 × 2 × 1 = 120). For larger values, the exact result appears in a scrollable field.
- Explore properties: The results panel shows the number of digits in the factorial result and the number of trailing zeros. These properties are mathematically interesting and have practical applications in number theory.
The calculator uses JavaScript BigInt for exact arbitrary-precision computation, so every digit of the result is correct even for very large factorials like 500! (which has 1,135 digits). All calculations run locally in your browser.
Factorial Formula and Properties
Factorial Definition
n! = n × (n-1) × (n-2) × ... × 2 × 1 Recursive Definition
n! = n × (n-1)!, with 0! = 1 Stirling's Approximation (for large n)
n! ≈ √(2πn) × (n/e)^n Trailing Zeros Formula
zeros = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ⌊n/625⌋ + ... Variables Explained
- n: A non-negative integer (0, 1, 2, 3, ...) for which the factorial is calculated.
- n!: The factorial of n — the product of all positive integers from 1 to n.
- 0!: Defined as 1 by convention, necessary for combinatorial formulas to work correctly.
- e: Euler's number (approximately 2.71828), used in Stirling's approximation.
- π (pi): Approximately 3.14159, also appears in Stirling's approximation.
Step-by-Step Example
Calculate 7! and find the number of trailing zeros.
- Write out the multiplication: 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1
- Multiply step by step: 7 × 6 = 42
- 42 × 5 = 210
- 210 × 4 = 840
- 840 × 3 = 2,520
- 2,520 × 2 = 5,040
- 5,040 × 1 = 5,040
- Trailing zeros: ⌊7/5⌋ = 1 (7! = 5,040 has 1 trailing zero)
The factorial 7! = 5,040. It has 4 digits and 1 trailing zero. The trailing zero comes from the single factor of 5 in the product (from 5 itself). The factor of 2 to pair with it comes from any of the even numbers (2, 4, 6).
Practical Examples
Example 1: Rachel's Seating Arrangement Problem
Rachel is organizing a dinner party for 8 guests at a rectangular table. She wants to know how many different seating arrangements are possible.
- For 8 guests in 8 seats, the number of arrangements is 8!
- 8! = 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 40,320
- If seating is circular (round table): (8-1)! = 7! = 5,040
There are 40,320 possible seating arrangements for a rectangular table and 5,040 for a round table (circular permutations divide by n because rotations are equivalent). Rachel realizes that trying every arrangement would take far too long and decides to seat people strategically based on conversation compatibility instead.
Example 2: Professor Kim's Combinatorics Lesson
Professor Kim is teaching students about the connection between factorials and combinations. She asks: "In how many ways can you choose 4 books from a shelf of 10?"
- Using the combination formula: C(10, 4) = 10! / (4! × 6!)
- 10! = 3,628,800
- 4! = 24
- 6! = 720
- C(10, 4) = 3,628,800 / (24 × 720) = 3,628,800 / 17,280 = 210
There are 210 ways to choose 4 books from 10. Professor Kim demonstrates the cancellation shortcut: instead of computing the full factorials, calculate (10 × 9 × 8 × 7) / (4 × 3 × 2 × 1) = 5,040 / 24 = 210. This avoids dealing with large intermediate numbers. For more combinatorics problems, use our permutation and combination calculator.
Example 3: Alex's Probability Computation
Alex is computing the probability of dealing a specific 5-card poker hand. He needs to calculate C(52, 5) — the total number of possible 5-card hands from a standard 52-card deck.
- C(52, 5) = 52! / (5! × 47!)
- Simplified: (52 × 51 × 50 × 49 × 48) / (5 × 4 × 3 × 2 × 1)
- Numerator: 311,875,200
- Denominator: 120
- C(52, 5) = 2,598,960
There are 2,598,960 possible 5-card poker hands. Alex can now calculate specific hand probabilities: a royal flush has 4 possible hands, so P(royal flush) = 4 / 2,598,960 = 0.000154% or about 1 in 649,740. Understanding factorials is essential for these probability calculations.
Factorial Reference Table
| n | n! | Digits | Trailing Zeros |
|---|---|---|---|
| 0 | 1 | 1 | 0 |
| 5 | 120 | 3 | 1 |
| 10 | 3,628,800 | 7 | 2 |
| 15 | 1,307,674,368,000 | 13 | 3 |
| 20 | 2,432,902,008,176,640,000 | 19 | 4 |
| 50 | 3.04 × 10⁶⁴ | 65 | 12 |
| 100 | 9.33 × 10¹⁵⁷ | 158 | 24 |
| 500 | 1.22 × 10¹¹³⁴ | 1,135 | 124 |
| 1000 | 4.02 × 10²⁵⁶⁷ | 2,568 | 249 |
Tips and Complete Guide
Efficient Factorial Computation
When using factorials in formulas, always simplify before computing. For C(20, 3) = 20!/(3! × 17!), do not compute 20! then divide by 3! × 17!. Instead, cancel the 17!: (20 × 19 × 18)/(3 × 2 × 1) = 6,840/6 = 1,140. This avoids dealing with astronomically large intermediate numbers and prevents overflow errors. Our calculator handles the full computation, but understanding simplification is essential for manual work and programming.
Factorials in Taylor Series
Factorials appear in the denominators of Taylor series, which are used to approximate functions. The exponential function e^x = 1 + x + x²/2! + x³/3! + x⁴/4! + ... . The sine function sin(x) = x - x³/3! + x⁵/5! - x⁷/7! + ... . The rapid growth of factorials in the denominator ensures these series converge. This is how calculators and computers actually compute trigonometric and exponential functions internally.
Double Factorials and Subfactorials
Beyond regular factorials, mathematicians use double factorials and subfactorials. The double factorial n!! multiplies every other number: 7!! = 7 × 5 × 3 × 1 = 105, and 8!! = 8 × 6 × 4 × 2 = 384. The subfactorial !n counts derangements (permutations where no element appears in its original position). For example, !3 = 2 (the derangements of 3 are 1 and 2). The formula is !n = n! × Σ(-1)^k/k! for k from 0 to n.
Common Mistakes to Avoid
- Forgetting that 0! = 1: This is not intuitive but is mathematically necessary. Many students assume 0! = 0, which leads to errors in combinatorial formulas. Remember: 0! = 1 by definition.
- Computing full factorials unnecessarily: In expressions like n!/(n-k)!, cancel common terms. P(100, 3) = 100 × 99 × 98 = 970,200. Computing 100! and 97! separately is wasteful and can cause overflow.
- Assuming factorials exist for negatives or decimals: The factorial function n! is only defined for non-negative integers. For non-integer values, use the gamma function: Γ(n+1) = n! for integers, but Γ is defined for all complex numbers except non-positive integers.
- Underestimating factorial growth: Students often underestimate how fast factorials grow. 20! is already about 2.4 × 10^18. An algorithm with O(n!) complexity becomes infeasible beyond n ≈ 15-20 on modern computers.
- Using floating-point for exact counting: Standard floating-point numbers lose precision beyond about 18 significant digits (past 21!). For exact results with large factorials, arbitrary-precision arithmetic (like our BigInt implementation) is essential.
Frequently Asked Questions
A 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. By convention, 0! = 1 (this is mathematically necessary for combinatorial formulas to work correctly). Factorials grow extremely fast: 10! = 3,628,800 and 20! = 2,432,902,008,176,640,000. Our calculator handles values up to 1000 using arbitrary-precision arithmetic.
The definition 0! = 1 is not arbitrary — it is mathematically necessary for consistency. The recursive definition n! = n × (n-1)! requires 0! = 1 for 1! = 1 × 0! to work. It also ensures combinatorial formulas work correctly: C(n, 0) = n! / (0! × n!) = 1 (there is exactly one way to choose nothing). C(n, n) = n! / (n! × 0!) = 1 (one way to choose everything). Without 0! = 1, these fundamental counting formulas would break.
Factorials grow faster than exponential functions. While 2^10 = 1,024, we have 10! = 3,628,800. By 20!, the value exceeds 2.4 quintillion. 100! has 158 digits, and 1000! has 2,568 digits. Stirling's approximation estimates large factorials: n! ≈ √(2πn) × (n/e)^n. This growth rate is why factorials appear in complexity analysis — algorithms with n! time complexity (like brute-force permutation) become infeasible very quickly.
Trailing zeros in n! come from factors of 10, and since 10 = 2 × 5, each trailing zero requires one pair of factors 2 and 5. Since there are always more factors of 2 than 5, the number of trailing zeros equals the number of times 5 divides into n!. The formula is: trailing zeros = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ... For example, 100! has ⌊100/5⌋ + ⌊100/25⌋ = 20 + 4 = 24 trailing zeros.
Factorials are fundamental to combinatorics and probability. They appear in permutation formulas (nPr = n!/(n-r)!), combination formulas (nCr = n!/[r!(n-r)!]), the binomial theorem, Taylor series expansions, and probability distributions (Poisson, binomial). Practical applications include calculating lottery odds, scheduling problems, arrangement counting, cryptographic key spaces, and statistical analysis. In computer science, factorials appear in algorithm complexity analysis.
The gamma function Γ(n) extends the factorial to non-integer and complex values. For positive integers, Γ(n) = (n-1)!. For example, Γ(5) = 4! = 24. This extension allows computation of 'factorials' for values like 0.5: Γ(1.5) = (1/2)! = √π/2 ≈ 0.886. The gamma function is widely used in probability distributions (gamma, beta, chi-squared, Student's t), statistical analysis, and mathematical physics.
Our calculator uses two approaches. For n ≤ 170, standard floating-point arithmetic provides results (though with potential rounding for very large values). For n up to 1000, we use JavaScript's BigInt arbitrary-precision integers to compute exact results with every digit correct. The full exact result is displayed in a scrollable field. We also show the number of digits in the result and the count of trailing zeros, which are useful mathematical properties.
Related Calculators
Permutation & Combination Calculator
Calculate nPr and nCr using factorials for counting problems.
Probability Calculator
Use factorials in probability calculations for events and outcomes.
Statistics Calculator
Comprehensive descriptive statistics for data analysis.
Standard Deviation Calculator
Calculate standard deviation and variance for any dataset.
Scientific Calculator
Perform advanced calculations with scientific functions.
Percentage Calculator
Calculate percentages and proportions for everyday math.
Disclaimer: This calculator is for informational and educational purposes only. Results are estimates and may not reflect exact values.
Last updated: February 23, 2026
Sources
- Khan Academy — Factorials and Permutations: khanacademy.org
- NIST Digital Library of Mathematical Functions — Gamma Function: dlmf.nist.gov
- Math is Fun — Factorial: mathsisfun.com