Factorial Calculator — Free Online n! Solver Math Tool
Calculate the factorial of any non-negative integer instantly. Free factorial calculator showing the full n! product, ideal for probability and combinatorics.
Calculate Factorial
About this calculator
Factorial Calculator
Comprehensive Guide to Factorial Calculator
The Factorial Calculator evaluates the exact factorial value ($n!$) for non-negative integers and fractional arguments via the continuous Gamma function. In mathematics, combinatorics, and probability, the factorial represents the product of all positive integers less than or equal to $n$. Factorials quantify the explosive growth of permutations—the total number of distinct ways to arrange $n$ unique items in sequential order.
From calculating combinations and binomial coefficients to evaluating Taylor series expansions, quantum mechanical partition functions, and computational algorithm complexity, factorials are ubiquitous across pure mathematics and STEM applications.
How to Use the Factorial Calculator
- Enter the Integer ($n$): Input any non-negative integer ($n \ge 0$) into the calculation field.
- Review Exact vs. Scientific Notation: For $n \le 20$, view the exact 64-bit integer output. For $n > 20$, examine the exact arbitrary-precision BigInt representation alongside standard scientific notation.
- Inspect Stirling's Approximation: Compare the exact factorial against Stirling's asymptotic formula to evaluate percentage accuracy.
- Count Trailing Zeros: Check the exact count of trailing zeros generated by factors of 10 evaluated via Legendre's formula.
- Explore Fractional Arguments (Optional): Input half-integers (e.g., $0.5$ or $1.5$) to evaluate continuous factorials via Euler's Gamma function $\Gamma(n + 1)$.
The Calculator Formulas
Factorial algebraic equations, asymptotic approximations, and continuous integral representations:
1. Factorial Definition for Positive Integers:
n! = n × (n - 1) × (n - 2) × ... × 3 × 2 × 1 (for n ≥ 1)
2. Axiomatic Base Case:
0! = 1
3. Recursive Relation:
n! = n × (n - 1)!
(n - 1)! = n! / n
4. Stirling's Asymptotic Approximation:
n! ≈ √(2 × π × n) × (n / e)ⁿ
Ramanujan's Refinement:
ln(n!) ≈ n × ln(n) - n + (1/6) × ln[ n × (1 + 4n × (1 + 2n)) ] + (1/2) × ln(π)
5. Legendre's Formula for Trailing Zeros (Z):
Z(n!) = Σ_{k=1}^∞ floor( n / 5^k ) = floor(n / 5) + floor(n / 25) + floor(n / 125) + ...
6. Euler's Continuous Gamma Function (for real/complex z):
Γ(z) = ∫_0^∞ t^(z - 1) × e^(-t) dt
Where: n! = Γ(n + 1)
Half-integer example: (1/2)! = Γ(3/2) = (1/2) × √π ≈ 0.886227
Practical Examples
Example 1: Calculating 6! (Permutations of Books on a Shelf)
A student wants to know how many distinct sequential ways 6 unique textbooks can be arranged on a study shelf.
Parameter: n = 6
Formula: 6! = 6 × 5 × 4 × 3 × 2 × 1
Calculation:
6 × 5 = 30
30 × 4 = 120
120 × 3 = 360
360 × 2 = 720
720 × 1 = 720
Result: There are exactly 720 unique arrangements.
Example 2: Counting Trailing Zeros in 100!
Determine how many consecutive zeros appear at the end of $100!$ without multiplying all one hundred numbers.
Parameter: n = 100
Legendre Formula: Z(100!) = floor(100 / 5) + floor(100 / 25) + floor(100 / 125) + ...
Calculation:
floor(100 / 5) = 20
floor(100 / 25) = 4
floor(100 / 125) = 0 (Terminates since 5³ > 100)
Total Trailing Zeros = 20 + 4 = 24 zeros
Result: 100! ends with exactly 24 zeros (ending in ...000000000000000000000000).
Key Concepts & Essential Terminology
The factorial of a non-negative integer $n$, symbolized by an exclamation point ($n!$), is the product of all positive integers less than or equal to $n$:
n! = n × (n - 1) × (n - 2) × ... × 3 × 2 × 1
By mathematical convention and axiomatic definition, $0! = 1$. This identity is essential for preserving the recursive relation $n! = rac{(n+1)!}{n+1}$, ensuring that the binomial coefficient formula $inom{n}{0} = rac{n!}{0! n!} = 1$ remains consistent, and maintaining the power series definition of the exponential function $e^x = sum_{k=0}^infty rac{x^k}{k!}$.
Factorials govern permutations, combinations, Taylor series expansions, hypergeometric distributions, statistical thermodynamics (Maxwell-Boltzmann and Fermi-Dirac statistics), and quantum mechanics.
Factorial Values and Integer Data Type Limits (n = 0 to 20)
The table below details exact factorial values from 0! through 20!, illustrating integer boundary limits across hardware programming data types:
| Integer (n) | Exact Value (n!) | Trailing Zeros | Computational Data Type Limit |
|---|---|---|---|
| 0! | 1 | 0 | Axiomatic base case; 8-bit unsigned integer |
| 1! | 1 | 0 | 8-bit unsigned integer (0 to 255) |
| 2! | 2 | 0 | 8-bit unsigned integer |
| 3! | 6 | 0 | 8-bit unsigned integer |
| 4! | 24 | 0 | 8-bit unsigned integer |
| 5! | 120 | 1 | Fits in 8-bit unsigned integer (max 255) |
| 6! | 720 | 1 | 16-bit unsigned integer (max 65,535) |
| 7! | 5,040 | 1 | 16-bit unsigned integer; Plato's ideal municipal size |
| 8! | 40,320 | 1 | 16-bit unsigned integer |
| 9! | 362,880 | 1 | 32-bit signed integer (max ~2.147 × 10⁹) |
| 10! | 3,628,800 | 2 | 32-bit signed integer |
| 11! | 39,916,800 | 2 | 32-bit signed integer |
| 12! | 479,001,600 | 2 | Maximum factorial in 32-bit signed int (13! overflows) |
| 13! | 6,227,020,800 | 2 | 64-bit signed integer (max ~9.223 × 10¹⁸) |
| 14! | 87,178,291,200 | 3 | 64-bit signed integer |
| 15! | 1,307,674,368,000 | 3 | 64-bit signed integer |
| 16! | 20,922,789,888,000 | 3 | 64-bit signed integer |
| 17! | 355,687,428,096,000 | 3 | 64-bit signed integer |
| 18! | 6,402,373,705,728,000 | 3 | 64-bit signed integer |
| 19! | 121,645,100,408,832,000 | 3 | 64-bit signed integer |
| 20! | 2,432,902,008,176,640,000 | 4 | Maximum factorial in 64-bit signed int (21! overflows) |
Large Factorial Milestones and Computational Overflow Thresholds
Beyond 20!, factorials grow at super-exponential speed, exceeding standard 64-bit integer registers and requiring arbitrary-precision arithmetic (such as JavaScript BigInt or Python arbitrary-precision integers):
| Milestone (n!) | Approximate Scientific Notation | Trailing Zeros | Significance & System Boundary |
|---|---|---|---|
| 21! | 5.10909 × 10¹⁹ | 4 | Overflows standard 64-bit signed integer; requires BigInt |
| 22! | 1.12400 × 10²¹ | 4 | Exceeds 1 sextillion; requires BigInt |
| 25! | 1.55112 × 10²⁵ | 6 | First double trailing-zero step (divisible by 5² = 25) |
| 52! | 8.06582 × 10⁶⁷ | 12 | Total unique permutations of a standard 52-card deck |
| 70! | 1.19786 × 10¹⁰⁰ | 16 | Exceeds a Googol (10¹⁰⁰); ~1.198 googols |
| 100! | 9.33262 × 10¹⁵⁷ | 24 | Standard benchmark; 158 decimal digits, 24 trailing zeros |
| 170! | 7.25742 × 10³⁰⁶ | 41 | Maximum factorial in IEEE 754 64-bit float (171! = Infinity) |
Algorithm Asymptotic Complexity Hierarchy (Big-O Order)
| Complexity Class | Big-O Notation | Operations for n = 10 | Operations for n = 20 | Operations for n = 50 | Benchmark Algorithm Example |
|---|---|---|---|---|---|
| Constant | O(1) | 1 | 1 | 1 | Hash table lookup, array index access |
| Logarithmic | O(log n) | 3.3 | 4.3 | 5.6 | Binary search on sorted array |
| Linear | O(n) | 10 | 20 | 50 | Single-pass array traversal, sum |
| Linearithmic | O(n log n) | 33 | 86 | 282 | Merge sort, Heapsort, Fast Fourier Transform (FFT) |
| Quadratic | O(n²) | 100 | 400 | 2,500 | Bubble sort, nested pairwise comparison |
| Cubic | O(n³) | 1,000 | 8,000 | 125,000 | Standard matrix multiplication, Gaussian elimination |
| Exponential | O(2ⁿ) | 1,024 | 1,048,576 | 1.126 × 10¹⁵ | Recursive Fibonacci, power set generation |
| Factorial | O(n!) | 3,628,800 | 2.433 × 10¹⁸ | 3.041 × 10⁶⁴ | Traveling Salesperson brute force, Heap's permutation generator |
Empirical Axioms & Mathematical Theorems
- Stirling's Asymptotic Formula: Computing large factorials by repeated multiplication is computationally slow. Scottish mathematician James Stirling derived the asymptotic relation:
n! ≈ √(2πn) × (n / e)ⁿ
Taking the natural logarithm yields Ramanujan's refined approximation:
ln(n!) ≈ n ln(n) - n + (1/2) ln(2πn) + 1/(12n) - 1/(360n³)
- Euler's Gamma Function Continuous Extension: To define factorials for non-integers, fractions, and negative non-integers, Leonhard Euler introduced the Gamma function:
Γ(z) = ∫_0^∞ t^(z - 1) e^(-t) dt
Using integration by parts, $Gamma(z + 1) = z Gamma(z)$. For positive integers, $Gamma(n + 1) = n!$. This extension reveals exact values for half-integers:
Γ(1/2) = √π → (-1/2)! = √π ≈ 1.77245385
(1/2)! = Γ(3/2) = (1/2) Γ(1/2) = (1/2) √π ≈ 0.88622692
- Legendre's Formula for Trailing Zeros: The number of trailing zeros in the decimal representation of $n!$ depends on the number of prime factor pairs of $2$ and $5$. Because factors of 2 are strictly more abundant than factors of 5, the number of trailing zeros $Z(n!)$ is given by Legendre's series:
Z(n!) = ∑_{k=1}^∞ ⌊ n / 5^k ⌋ = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ...
How Factorial Calculation Works
Factorial computation combines recursive number theory, prime factorization algorithms, and asymptotic series expansions:
1. Proof of the Identity 0! = 1
The base case $0! = 1$ is mathematically mandatory for three reasons:
- Recursive Consistency: The recursive formula states $n! = n imes (n - 1)!$. Setting $n = 1$ yields $1! = 1 imes (1 - 1)! implies 1 = 1 imes 0! implies 0! = 1$.
- Combinatorial Combinations: The formula for choosing 0 items from $n$ items is $inom{n}{0} = rac{n!}{0! (n - 0)!} = rac{n!}{0! n!}$. For this to equal 1 (the single empty set), $0!$ must equal 1.
- Empty Product Convention: In algebra, multiplying zero factors yields the multiplicative identity ($1$), just as summing zero terms yields the additive identity ($0$).
2. High-Precision BigInt Factorial Multiplication
Because factorials exceed 64-bit integer limits at $n = 21$, software calculators implement prime-swing algorithms or binary splitting trees. By factoring $n!$ into its constituent prime powers $p^k$ using Legendre's theorem, computers multiply pre-factored primes rather than performing $n$ large sequential multiplications, accelerating calculation speeds by over $80%$.
3. Factorial Growth in Cryptography and Combinatorics
The sheer scale of factorial growth safeguards cryptographic systems. A standard 52-card deck has $52! approx 8.0658 imes 10^{67}$ permutations. If every human on Earth shuffled a deck 1,000 times per second since the Big Bang ($13.8 ext{ billion years}$), the total shuffles would represent an infinitesimal fraction of $52!$. Every properly randomized shuffle creates a card sequence that has almost certainly never existed before.
Common Factorial Calculator Mistakes to Avoid
- Assuming $0! = 0$: Treating $0!$ as zero rather than $1$, which causes division-by-zero errors in combinations, permutations, and binomial theorem expansions.
- Attempting to Factorial Negative Integers: Entering negative integers into standard factorial formulas. Factorials for negative integers are mathematically undefined (poles of the Gamma function where $Gamma(z) = pminfty$).
- Integer Overflow in Custom Code: Writing simple loops in languages with fixed-width integers (like C, C++, or Java
intandlong), which silently overflow to negative values at $13!$ (32-bit) or $21!$ (64-bit). - Confusing Factorials ($n!$) with Subfactorials ($!n$): Mistaking standard permutations for derangements (permutations where no element appears in its original position), which is denoted $!n approx n! / e$.
- Believing Factorials Only Apply to Whole Numbers: Assuming non-integers cannot have factorials, overlooking Euler's Gamma function where half-integers have closed-form values involving $sqrt{pi}$.
Frequently Asked Questions
Why does 0 factorial equal 1?
0! equals 1 by mathematical definition and algebraic necessity. It satisfies the recursive formula n! = n × (n - 1)!, ensures that combinations C(n, 0) and C(n, n) equal 1, and follows the empty product rule in algebra.
What is the highest factorial that fits in a standard computer integer?
In standard 32-bit signed integers, 12! (479,001,600) is the maximum before overflow. In 64-bit signed integers, 20! (2,432,902,008,176,640,000) is the maximum. Larger factorials require BigInt arbitrary-precision data types.
Can negative numbers have factorials?
Negative integers (-1, -2, -3, etc.) do not have factorials; their values are undefined (poles of the Gamma function). However, negative non-integers (such as -1/2) do have valid real factorials via the Gamma function: (-1/2)! = Γ(1/2) = √π ≈ 1.7725.
What is Stirling's approximation?
Stirling's approximation is a mathematical formula that estimates large factorials without multiplying: n! ≈ √(2πn) × (n/e)ⁿ. Its accuracy increases as n grows larger, with error dropping below 0.1% for n ≥ 100.
How do you find the number of trailing zeros in a factorial?
Use Legendre's formula: sum the integer quotients of n divided by successive powers of 5 (floor(n/5) + floor(n/25) + floor(n/125) + ...). Zeros are created by factors of 10 (2 × 5), and factors of 5 are the limiting factor.
What is a double factorial (n!!)?
A double factorial multiplies only integers that have the same parity (odd or even) as n. For example, 7!! = 7 × 5 × 3 × 1 = 105, and 8!! = 8 × 6 × 4 × 2 = 384. It is distinct from calculating (n!)!.
Conclusion
The Factorial Calculator provides high-precision evaluation of factorial expansions, asymptotic approximations, and continuous Gamma functions. By understanding computational overflow boundaries, permutation counting, and Legendre's trailing zero laws, users can analyze combinatorial systems with absolute accuracy.
Related Calculators
Sources & References
Technical & General Calculation Disclaimer
This calculation tool applies standard mathematical, scientific, or engineering formulas. While designed for precision, output values are estimates and should be independently verified for commercial, structural, or safety-critical applications.
Comments
Loading comments…
Related Math Calculators
Explore more tools to continue your analysis
Permutations Calculator
Calculate nPr permutations (order important).
Combinations Calculator
Calculate nCr combinations (order unimportant).
Prime Number Calculator
Check if a number is prime and find factors.
Factors Calculator
Find all factors of a number.
Prime Factorization Calculator
Decompose integer into prime factors.
Exponent Calculator
Calculate exponents and powers.
Scientific Calculator
Advanced math operations.
Logarithm Calculator
Calculate logarithms (log, ln) with any base.