Factorial Calculator

Enter a non-negative integer n to compute n! (factorial).

Back to all tools on ToolForge

More in Calculators

n



Result

About Factorial Calculator

This factorial calculator computes `n!` for a non-negative integer.

It is useful for permutations, combinations, probability problems and classroom math where factorial values come up often.

Factorial Formula and Examples

// Factorial definition:
// n! = n × (n-1) × (n-2) × ... × 2 × 1
// 0! = 1 (by convention)

// Examples:
// 0! = 1
// 1! = 1
// 2! = 2 × 1 = 2
// 3! = 3 × 2 × 1 = 6
// 4! = 4 × 3 × 2 × 1 = 24
// 5! = 5 × 4 × 3 × 2 × 1 = 120
// 10! = 3,628,800
// 20! = 2,432,902,008,176,640,000

// JavaScript implementation (iterative):
function factorial(n) {
  let result = 1;
  for (let i = 2; i <= n; i++) {
    result *= i;
  }
  return result;
}

Factorial Values Reference Table

nn!Scientific Notation
011×10^0
111×10^0
222×10^0
366×10^0
4242.4×10^1
51201.2×10^2
67207.2×10^2
75,0405.04×10^3
840,3204.03×10^4
9362,8803.63×10^5
103,628,8003.63×10^6
151,307,674,368,0001.31×10^12
202,432,902,008,176,640,0002.43×10^18

Permutations and Combinations

// Permutations (order matters):
// P(n,r) = n! / (n-r)!
// Example: Arrange 3 books from 5: P(5,3) = 5!/2! = 60

// Combinations (order doesn't matter):
// C(n,r) = n! / (r! × (n-r)!)
// Example: Choose 3 books from 5: C(5,3) = 5!/(3!×2!) = 10

// Binomial coefficient (n choose r):
// C(n,r) = n! / (r! × (n-r)!)
// Used in binomial theorem: (a+b)^n = Σ C(n,k) × a^(n-k) × b^k

Stirling's Approximation

For large n, factorial can be approximated:

n! ≈ √(2πn) × (n/e)^n

// More accurate version:
n! ≈ √(2πn) × (n/e)^n × (1 + 1/(12n))

// Example: 10!
// Exact: 3,628,800
// Stirling: √(20π) × (10/e)^10 ≈ 3,598,696
// Error: ~0.8%

Frequently Asked Questions

What is a factorial and how is it calculated?
The factorial of n (denoted n!) is the product of all positive integers from 1 to n. Formula: n! = n × (n-1) × ... × 2 × 1. By convention, 0! = 1. Example: 5! = 5×4×3×2×1 = 120. Factorials grow extremely fast: 10! = 3,628,800, 20! ≈ 2.4 quintillion.
What are factorials used for in mathematics?
Factorials are fundamental in: combinatorics (counting permutations and combinations), probability theory (calculating odds), calculus (Taylor series coefficients), statistics (binomial distributions), and algebra (binomial theorem). They count the number of ways to arrange n distinct objects.
What is the recursive formula for factorials?
The recursive definition is: n! = n × (n-1)! with base case 0! = 1. This means 5! = 5 × 4! = 5 × 24 = 120. Recursive formulas are elegant but iterative calculation is more efficient for large numbers to avoid stack overflow in programming.
How fast do factorials grow?
Factorials grow faster than exponential functions. Stirling's approximation: n! ≈ √(2πn) × (n/e)^n. For large n: 10! = 3.6M, 15! = 1.3T, 20! = 2.4 quintillion, 52! ≈ 8×10^67 (more than atoms in the observable universe). JavaScript can accurately compute up to 170! before overflow.
What is the double factorial notation?
Double factorial (n!!) multiplies every other integer: n!! = n × (n-2) × (n-4) × ... For odd n: 7!! = 7×5×3×1 = 105. For even n: 8!! = 8×6×4×2 = 384. By convention: 0!! = 1 and (-1)!! = 1. Used in combinatorics and special function theory.
How do you calculate permutations and combinations using factorials?
Permutations (order matters): P(n,r) = n!/(n-r)!. Combinations (order doesn't matter): C(n,r) = n!/(r!×(n-r)!). Example: From 52 cards, there are C(52,5) = 2,598,960 possible 5-card hands, but P(52,5) = 311,875,200 ordered sequences.