Factorial Calculator
Calculate the factorial of a non-negative integer
Category: Mathematics
Factorial Calculator Inputs
Factorial Calculator Formula
Equation
n! = n × (n-1) × (n-2) × ... × 2 × 1
Excel Formula
=n!=n*(n-1)*(n-2)*...*2*1
Variables
- Number (n) — Enter a non-negative integer to calculate its factorial (0-1000). You can use commas for formatting.
- Show Steps — Display detailed step-by-step calculation
- Include Stirling's Approximation — Show Stirling's approximation for comparison (useful for large numbers)
How the Factorial Calculator Works
The factorial function is one of the most fundamental and rapidly growing functions in mathematics. It appears in combinatorics, probability theory, calculus, number theory, and many other areas. Understanding factorials is essential for counting problems, probability calculations, and advanced mathematical concepts. The factorial function grows faster than exponential functions and is central to many areas of mathematics.
The core relationship is n! = n \times (n-1) \times (n-2) \times ... \times 2 \times 1. Typical inputs include Number (n), Show Steps, Include Stirling's Approximation.
Enter your values in the factorial calculator above, review the step-by-step solution, and compare against the worked examples below so you can see how each input changes the result. This free online mathematics tool is built for homework, design checks, and professional verification.
Factorial Calculator Theory & Explanation
Definition and Basic Properties
The factorial of a non-negative integer n, denoted n!, is the product of all positive integers from 1 to n. By definition, 0! = 1 and 1! = 1. This definition ensures that many mathematical formulas work correctly, especially in combinatorics. The factorial function is defined for non-negative integers only.
n! = \begincases 1 & \textif n = 0 \\ n × (n-1) × (n-2) × ·s × 2 × 1 & \textif n ≥ 1 \endcases
Recursive Definition and Properties
Factorials can be defined recursively: n! = n × (n-1)! for n ≥ 1, with base case 0! = 1. This leads to important properties: (n+1)! = (n+1) × n!, and n! = n × (n-1) × (n-2)! for n ≥ 2. The recursive definition is fundamental to understanding factorial properties and computational algorithms.
n! = n × (n-1)! \text for n ≥ 1, \quad 0! = 1
Mathematical Properties and Identities
Factorials satisfy several important mathematical properties: n! divides (n+k)! for any k ≥ 0, (n+1)! = (n+1) × n!, and n! = n × (n-1)! × (n-2)! × ... × 1. These properties are crucial for simplifying complex expressions involving factorials.
((n+k)!)/(n!) = (n+1)(n+2)·s(n+k), \quad \textfor k ≥ 1
Rapid Growth and Asymptotic Behavior
Factorials grow extremely rapidly, faster than any exponential function. For large n, Stirling's approximation gives n! ≈ √(2πn) × (n/e)^n. This approximation becomes more accurate as n increases and is useful for estimating large factorials. The growth rate is super-exponential.
n! ≈ √(2π n) ((n)/(e))^n \text for large n
Stirling's Approximation and Error Analysis
Stirling's approximation provides an excellent estimate for large factorials. The relative error decreases as n increases, typically within 1% for n > 10. More refined versions include correction terms for even better accuracy.
n! ≈ √(2π n) ((n)/(e))^n (1 + (1)/(12n) + (1)/(288n^2) + ·s)
Applications in Combinatorics and Counting
Factorials are fundamental in counting problems. The number of permutations of n distinct objects is n!. They appear in combinations C(n,r) = n!/(r!(n-r)!) and permutations P(n,r) = n!/(n-r)!. These formulas are essential for probability and statistics.
P(n,r) = (n!)/((n-r)!), \quad C(n,r) = (n!)/(r!(n-r)!) = \binomnr
Applications in Probability Theory
Factorials appear extensively in probability calculations, especially in discrete probability distributions. They are used in calculating probabilities of arrangements, combinations, and in the binomial distribution. The multinomial distribution also heavily relies on factorials.
P(X = k) = C(n,k) × p^k × (1-p)^n-k = (n!)/(k!(n-k)!) × p^k × (1-p)^n-k
Taylor Series and Calculus Applications
Factorials appear in Taylor series expansions: e^x = Σ(x^n/n!) for all x. They also appear in derivatives of power functions and in the definition of the exponential function. The factorial denominators ensure convergence of these series.
e^x = Σ_n=0^∞ (x^n)/(n!) = 1 + x + (x^2)/(2!) + (x^3)/(3!) + ·s
Gamma Function Extension
The gamma function Γ(z) extends factorial to complex numbers: Γ(n+1) = n! for positive integers n. This allows factorial to be defined for non-integer values and is important in advanced mathematics, including complex analysis and number theory.
\Gamma(n+1) = n! \text for n \in \mathbbN, \quad \Gamma(z) = ∫_0^∞ t^z-1 e^-t dt
Number Theory and Prime Factorization
Factorials have interesting properties in number theory. For example, n! contains all prime numbers up to n as factors. The number of trailing zeros in n! is given by the sum of floor(n/5^k) for k = 1, 2, 3, ...
\textNumber of trailing zeros in n! = Σ_k=1^∞ \lfloor (n)/(5^k) \rfloor
Computational Algorithms and Optimization
For large n, direct calculation of n! becomes impractical due to rapid growth. Special algorithms include memoization, log-space calculations, and Stirling's approximation. The largest factorial that can be stored in standard data types is typically around 170! for double precision.
\log(n!) = Σ_k=1^n \log(k) \text (for log-space calculations)
Applications in Physics and Engineering
Factorials appear in statistical mechanics (partition functions), quantum mechanics (Fermi-Dirac and Bose-Einstein statistics), and engineering (signal processing, error correction codes). They are fundamental to understanding complex systems with discrete states.
Z = Σ_n=0^∞ \fracg^n e^-β E_nn! \text (partition function)
Factorial Calculator Worked Examples
Worked Example
Inputs
- number: 5
Result: 120
Explanation
5! = 5 × 4 × 3 × 2 × 1 = 120.
Zero Factorial
Inputs
- number: 0
- show_steps: yes
- include_approximation: no
Result: 1
Explanation
0! = 1 by definition. This convention makes many mathematical formulas work correctly.
Common Factorial Calculator Use Cases
- Homework and exam practice
- Engineering and science coursework
- Quick verification of hand calculations
- Factorial homework and study
- Factorial design and analysis
Factorial Calculator FAQs
What is 0! (zero factorial) and why is it 1?
0! is defined to be 1. This is a mathematical convention that makes many formulas work correctly, especially in combinatorics and probability. For example, it ensures that C(n,0) = 1 and P(n,0) = 1, which makes sense combinatorially.
Can factorials be calculated for negative numbers or decimals?
No, factorials are only defined for non-negative integers. For negative numbers or non-integers, you would need to use the gamma function, which extends factorial to real and complex numbers: Γ(n+1) = n! for positive integers n.
Why do factorials grow so quickly?
Factorials grow exponentially because each multiplication adds another factor. For example, 10! = 3,628,800, while 20! has 19 digits. This rapid growth makes factorials useful for counting large numbers of arrangements but also means they quickly exceed computational limits.
What is the relationship between factorial and permutation?
The number of ways to arrange n distinct objects is n! (n factorial). This is because you have n choices for the first position, (n-1) for the second, (n-2) for the third, and so on until you have only 1 choice for the last position.
What is Stirling's approximation and when is it useful?
Stirling's approximation is n! ≈ √(2πn) × (n/e)^n. It becomes more accurate as n increases and is useful for estimating large factorials when exact calculation is impractical. The approximation is within 1% for n > 10.
How are factorials used in probability and statistics?
Factorials appear in probability calculations, especially in discrete probability distributions. They are used in calculating probabilities of arrangements, combinations, and in the binomial distribution formula: P(X = k) = C(n,k) × p^k × (1-p)^(n-k).
What is the largest factorial that can be calculated accurately?
The largest factorial that can be accurately represented in standard floating-point formats is typically around 170!. Beyond this, the numbers become too large and lose precision. For larger factorials, Stirling's approximation or specialized algorithms are used.
How do factorials appear in calculus and Taylor series?
Factorials appear in Taylor series expansions, most notably: e^x = Σ(x^n/n!) for all x. They also appear in derivatives of power functions and in the definition of the exponential function. This connection between factorials and calculus is fundamental to mathematical analysis.