Factorial Calculator: n!, Gamma function, Stirling approximation

Factorial calculator n! for integers up to 170. Gamma function Γ(x) for reals, Stirling, double factorial n!!, subfactorial !n. Permutations, combinations.

Calculation parameters
Was this calculator useful?

Factorial: n! = n · (n−1) · ... · 1

The factorial of a positive integer n (written n!) is the product of all integers from 1 to n. Convention: 0! = 1. Explosive growth: 10! = 3,628,800, 20! ≈ 2.4 × 10¹⁸, 170! ≈ 7.3 × 10³⁰⁶ (double precision limit). Beyond, use Gamma function or BigInt. This calculator has 5 modes: integer factorial, double factorial n!!, subfactorial !n, Gamma Γ(x) for reals, Stirling approximation.

Fundamental formulas

  • n! = n · (n−1)! (recursive) with 0! = 1
  • n! = ∏ᵢ₌₁ⁿ i
  • Γ(n) = (n−1)! for positive integers
  • Stirling: n! ≈ √(2πn) · (n/e)ⁿ
  • Double: n!! = n·(n−2)·(n−4)·...
  • Subfactorial: !n = n!·Σₖ (−1)ᵏ/k!

Common factorials

nn!Digits
011
51203
103,628,8007
202.43×10¹⁸19
503.04×10⁶⁴65
1009.33×10¹⁵⁷158
1707.26×10³⁰⁶307 (double limit)

Examples

Example 1: permutations of 6

Arranging 6 people in a row: 6! = 720 ways.

Example 2: lottery combinations

Pick 6 from 90 (Superenalotto): C(90,6) = 622,614,630. Probability: 1 in 622M.

Example 3: card deck

52 cards shuffles: 52! ≈ 8.07 × 10⁶⁷. More than atoms on Earth (10⁵⁰).

Example 4: derangement

5 people hat swap: !5 = 44. ~37% of permutations are derangements.

Example 5: Stirling for n=20

Exact: 20! = 2,432,902,008,176,640,000. Stirling ~2.42×10¹⁸. Error ~0.42%.

Gamma function Γ(x)

Extension of factorial to reals/complexes:

  • Γ(n+1) = n! for positive integers
  • Γ(1/2) = √π ≈ 1.7725
  • Γ(x+1) = x·Γ(x)
  • Poles at 0, −1, −2, ...

Introduced by Euler 1729. Numeric via Lanczos (15 digits precision).

Stirling approximation (1730)

n! ≈ √(2πn) · (n/e)ⁿ

More accurate: ·(1 + 1/(12n) + 1/(288n²) − ...).

Error: ~1/(12n). n=10: 0.83%. n=100: 0.083%. Used in asymptotic analysis, statistical mechanics, number theory.

Double factorial n!!

Product of same-parity integers: n!! = n·(n−2)·(n−4)·...

Examples: 5!! = 5·3·1 = 15. 6!! = 48. 10!! = 3840.

Relations: (2n)!! = 2ⁿ·n!. Used in combinatorics (Dyck paths), physics (Gauss moment integrals).

Subfactorial !n

Counts permutations without fixed points (derangements):

!n = n!·Σₖ (−1)ᵏ/k!

Values: !1=0, !2=1, !3=2, !4=9, !5=44, !6=265.

lim !n/n! = 1/e ≈ 0.3679. 37% of any random permutation is a derangement.

Hat problem

N people deposit hats at entrance. Exit randomly. Probability nobody gets their own = !N/N! → 1/e as N→∞. 36.79% at infinity.

Permutations and combinations

  • P(n,k) = n!/(n−k)! — ordered selections
  • C(n,k) = n!/(k!·(n−k)!) — unordered selections
  • Binomial (ⁿₖ) = C(n,k)

Example: lottery 6/49 → C(49,6) = 13,983,816 possibilities.

Applications

Combinatorics and probability

  • Lotteries (SuperEnalotto, Powerball, EuroMillions)
  • Poker: C(52,5) = 2,598,960 hands
  • Passwords
  • Graph paths
  • Anagrams

Statistics

  • Poisson: P(k) = e^(−λ)·λᵏ/k!
  • Binomial: C(n,k)·pᵏ·(1−p)^(n−k)
  • Chi-square

Physics and chemistry

  • Statistical mechanics: S = k·log(Ω)
  • Quantum mechanics
  • Taylor series: e^x = Σ xⁿ/n!
  • Special functions (Bessel, Legendre)

Computer science

  • Recursive algorithms
  • O(n!) complexity: traveling salesman brute force
  • Permutation generation

Engineering

  • Maxwell-Boltzmann distribution
  • Statistical quality control
  • System reliability

Taylor series with factorials

  • e^x = Σ xⁿ/n!
  • sin(x) = Σ (−1)ⁿ x^(2n+1)/(2n+1)!
  • cos(x) = Σ (−1)ⁿ x^(2n)/(2n)!
  • (1+x)^α = Σ C(α,n)·xⁿ

History

Clavius (1603): first use in recreational math.

Kramp (1808): introduces "n!" notation.

Euler (1729): extends to Gamma function for reals. Extraordinary feat: generalizing n! to all numbers.

Stirling (1730): asymptotic approximation.

Ramanujan (1914): extraordinary series for factorials.

Trivia

  • Number of digits of n!: log₁₀(n!) ≈ log₁₀(√(2πn)) + n·log₁₀(n/e)
  • Trailing zeros of n!: = number of 5s in factorization = Σⁱₖ₌₁ ⌊n/5ᵏ⌋
  • Example: 25! has 5+1 = 6 trailing zeros

FAQ

Why 0! = 1?

Convention. Empty product = 1 (neutral element). Enables elegant formulas: C(n,0) = 1. Consistent with Γ(1) = 1.

Why does n! explode?

Multiplies all positive integers up to n. 10! = 3.6M, 20! is 18 digits, 100! has 158 digits. Grows faster than any exponential.

How to calculate large n!?

(

  • Exact with BigInt; (
  • Stirling approximation (~1% error); (
  • Gamma via Lanczos (15 digits). For n>170 use BigInt (double overflow)

Gamma function?

Extension to reals/complexes: Γ(n) = (n−1)! for positive integers. Γ(1/2) = √π. Poles at 0, −1, −2. Fundamental in statistics, physics.

Difference factorial vs double factorial?

n! all integers down to 1. n!! same-parity only. Ex: 5!=120, 5!!=15.

Use of derangements?

Permutations without fixed points. Hat problem, secret santa, file matching, cryptography.

Fast computation of n!?

Stirling: n! ≈ √(2πn)(n/e)ⁿ. For n=100: 9.32×10¹⁵⁷ (exact 9.33). ~0.08% error. Good enough for most non-financial apps.

Common errors

  • 0! = 0 (FALSE, it's 1)
  • Factorial of non-integers (only Gamma)
  • Silent overflow beyond 170 (Infinity in JS)
  • Confusing n!! with (n!)!
  • Negative factorials (undefined, Gamma poles)
  • Floating point for exact combinatorics

Updated July 2026

Frequently Asked Questions

What is the factorial of a number?

The factorial of n, written n!, is the product of all positive integers from 1 to n: n! = n·(n−1)·...·2·1. For example 5! = 5·4·3·2·1 = 120. It counts the number of ways to order n distinct objects and is the fundamental quantity of combinatorics.

Why is 0! = 1?

By convention 0! = 1, for two reasons. Combinatorially, there is exactly one way to order zero objects (the empty set). Formally, it is the empty product, which equals 1 by definition. This convention keeps combination formulas and Taylor series consistent, where 0! appears in the denominator.

How fast does the factorial grow?

The factorial grows faster than any exponential function: 10! = 3,628,800, 20! ≈ 2.4×10¹⁸, and 170! ≈ 7.3×10³⁰⁶, the limit of computers' double precision. Beyond 170! the value overflows and approximations such as Stirling's are used.

What is the Gamma function?

The Gamma function Γ extends the factorial to real and complex numbers. For integers Γ(n+1) = n!, but it is also defined between integers: for example Γ(1/2) = √π. Introduced by Euler in 1729, it is essential in statistics, quantum physics and number theory.

What is Stirling's approximation?

It is a formula to estimate large factorials: n! ≈ √(2πn)·(n/e)ⁿ. The relative error decreases as 1/(12n): about 0.83% for n = 10 and 0.08% for n = 100. It is fundamental in statistics, statistical mechanics and asymptotic analysis, where exact factorials would be incomputable.

What is the double factorial?

The double factorial n!! is the product of integers of the same parity as n down to n: n!! = n·(n−2)·(n−4)·... For example 5!! = 5·3·1 = 15 and 6!! = 6·4·2 = 48. Note: n!! is not (n!)!. It appears in combinatorics, Dyck paths and physics integrals.

What is the factorial used for?

The factorial is the basis of combinatorics: permutations of n objects are n!, combinations are C(n,k) = n!/(k!·(n−k)!). It is used in probability, Taylor series (where it appears in the denominator), statistics, cryptography and every counting problem.

Comments (0)

No comments yet. Be the first!