n!

Factorial Calculator

Compute n! for any integer from 0 to 170, with full step-by-step expansion.

Results

What Is a Factorial?

The factorial of a non-negative integer n, written 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. Factorials grow extremely fast — 10! = 3,628,800 and 20! ≈ 2.4 × 10¹⁸.

Definition and Base Cases

n! = n × (n−1)! for n ≥ 1, with the base case 0! = 1. This recursive definition shows how factorials build on each other. Why is 0! = 1? It ensures the formula for combinations works: C(n,0) = n!/(0!×n!) = 1, meaning there is exactly one way to choose 0 items from n.

Factorial Growth

Factorials grow faster than exponentials. 1!=1, 2!=2, 3!=6, 4!=24, 5!=120, 6!=720, 7!=5040, 8!=40320, 9!=362880, 10!=3628800. JavaScript can represent exact integers up to about 20! before floating-point precision issues appear. For larger values, scientific notation is used.

Applications

Factorials are central to combinatorics. The number of ways to arrange n distinct objects is n! (permutations). The number of ways to choose r from n is C(n,r) = n!/(r!×(n−r)!) (combinations). Factorials also appear in Taylor series expansions (eˣ = Σ xⁿ/n!) and probability calculations.

Stirling's Approximation

For large n, n! ≈ √(2πn) × (n/e)ⁿ. This approximation is useful in statistical mechanics, information theory, and asymptotic analysis of algorithms.

Worked Example: Counting Arrangements

How many different orders can 5 books be placed on a shelf? The answer is 5! = 5 × 4 × 3 × 2 × 1 = 120. If only 3 of the 5 books are selected and arranged (permutation P(5,3)): P(5,3) = 5!/(5−3)! = 120/2 = 60 ordered arrangements. If order doesn't matter (combination C(5,3)): C(5,3) = 5!/(3!×2!) = 120/(6×2) = 10 ways.

Factorial Values Quick Reference

nn!Approximate
011
51201.20 × 10²
103,628,8003.63 × 10⁶
151,307,674,368,0001.31 × 10¹²
202,432,902,008,176,640,0002.43 × 10¹⁸
528.07 × 10⁶⁷ (deck of cards)

52! represents the number of ways a deck of cards can be shuffled. This number (≈8×10⁶⁷) exceeds the estimated number of atoms in the observable universe (≈10⁸⁰), meaning every well-shuffled deck arrangement is almost certainly unique in all of human history.

Frequently Asked Questions

0! = 1 by definition. This is not just convention — it makes the combination formula C(n,0) = 1 work correctly (there is exactly one way to choose nothing).

10! = 3,628,800. The product of all integers from 1 to 10.

Very fast. 20! ≈ 2.4 × 10¹⁸. 100! has 158 digits. 170! is the largest factorial a 64-bit floating-point number can represent (~7.3 × 10³⁰⁶).

Permutations (arrangements): n! ways to order n objects. Combinations: n!/(r!(n-r)!). Taylor series. Probability calculations.

n! = n × (n-1) × ... × 1. As n grows, you multiply by ever-larger numbers, while an exponential like 2ⁿ always multiplies by the same base 2.

The gamma function Γ(n) = (n−1)! extends factorials to non-integer and complex values. For a positive integer n: Γ(n) = (n−1)!. For half-integers: Γ(1/2) = √π ≈ 1.7725. The gamma function is defined by an integral and appears in probability distributions (gamma, chi-square, beta) and many areas of analysis.

Trailing zeros come from factors of 10 = 2 × 5. Since there are always more factors of 2 than 5 in n!, count the factors of 5: trailing zeros in n! = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ... For 100!: ⌊100/5⌋+⌊100/25⌋ = 20+4 = 24 trailing zeros.

Formula sources & accuracy standards: Calculator Methodology · Editorial Policy