Calculator.

Factorial Calculator.

Calculate the factorial (n!) of any non-negative integer instantly with step-by-step breakdown.

!

Enter a non-negative integer (0 to 170)

Quick Reference Table

0!1
1!1
2!2
3!6
4!24
5!120
6!720
7!5,040
8!40,320
9!362,880
10!3,628,800
12!479,001,600
15!1,307,674,368,000
20!2,432,902,008,176,640,000

5! (Factorial of 5)

120

Formula Expansion

5! = 5 × 4 × 3 × 2 × 1

Input Number

5

Number of Digits

3

Step-by-Step Calculation

2! = 1 × 2= 2
3! = 2 × 3= 6
4! = 6 × 4= 24
5! = 24 × 5= 120

Did You Know?

5! represents the number of ways to arrange 5 distinct objects in a row.

What is Factorial?

A factorial, denoted by n!, is the product of all positive integers from 1 to n. For example, 5! (read as "five factorial") equals 5 × 4 × 3 × 2 × 1 = 120. The factorial function is one of the most fundamental concepts in mathematics, particularly in combinatorics and probability theory.

By mathematical convention, 0! is defined to equal 1. This might seem counterintuitive, but it's essential for many formulas to work correctly, including the binomial coefficient and various counting formulas.

Factorial Formula

n! = n × (n-1) × (n-2) × ... × 3 × 2 × 1

Or recursively: n! = n × (n-1)! where 0! = 1

Examples

3! = 3 × 2 × 1 = 6

5! = 5 × 4 × 3 × 2 × 1 = 120

7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5,040

10! = 3,628,800

Common Uses of Factorial

  • Permutations: The number of ways to arrange n distinct objects is n!
  • Combinations: C(n,r) = n! / (r! × (n-r)!) calculates how many ways to choose r items from n items
  • Probability: Many probability calculations involve factorials, especially in binomial distributions
  • Taylor Series: Factorials appear in the denominators of Taylor series expansions (e.g., e^x, sin(x))
  • Computer Science: Used in algorithm analysis, counting problems, and recursive function design

Properties of Factorial

  • Factorial is only defined for non-negative integers
  • Factorials grow extremely fast - faster than exponential functions
  • n! = n × (n-1)! (recursive property)
  • For large n, Stirling's approximation can be used: n! ≈ √(2πn) × (n/e)^n

How Fast Factorials Grow, and Why This Tool Stops at 170

Put n! next to squaring and doubling and the gap becomes obvious. At n = 5 the three are close, but by n = 20 the factorial is already about 2.3 trillion times larger than 2²⁰. The table below tracks all three side by side.

nn! (factorial)2ⁿ (doubling)n² (squaring)
1121
51203225
103,628,8001,024100
151,307,674,368,00032,768225
202,432,902,008,176,640,0001,048,576400

That growth explains the 170 limit. This calculator holds results in BigInt, so every digit up to 170! is exact, but a raw 64-bit signed integer tops out at 2⁶³ − 1 = 9,223,372,036,854,775,807. Since 20! = 2,432,902,008,176,640,000 still fits and 21! ≈ 5.1 × 10¹⁹ does not, 21! is the first factorial to overflow a 64-bit int. A double-precision float reaches roughly 1.8 × 10³⁰⁸, and 170! ≈ 7.3 × 10³⁰⁶ squeaks under that ceiling while 171! ≈ 1.2 × 10³⁰⁹ does not. 170 is simply the last factorial a standard float can represent.

Worked Counting Examples

Permutations count ordered outcomes. To find how many ways 8 runners can take the top three medals, use P(8, 3) = 8! / 5! = 8 × 7 × 6 = 336. Combinations ignore order. The number of distinct 5-card poker hands from a 52-card deck is C(52, 5) = 52! / (5! × 47!) = 2,598,960. Notice the 47! cancels most of the 52!, so you never actually compute the full factorials, which is why these stay tractable long after n! itself becomes astronomical.

Stirling's Approximation in Practice

When you only need a ballpark, Stirling's formula n! ≈ √(2πn) × (n/e)ⁿ is fast and improves as n rises. The relative error drops from under 2% at n = 5 to well below half a percent by n = 20.

nExact n!Stirling estimateRelative error
5120≈ 118.01.65%
103,628,800≈ 3,598,6960.83%
202.43 × 10¹⁸≈ 2.42 × 10¹⁸0.42%

Trailing Zeros of n!

A trailing zero appears each time a factor of 10 = 2 × 5 enters the product, and 5s are always the scarce ingredient. Legendre's formula counts them by summing ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + …. For 100!, that is 20 + 4 + 0 = 24 trailing zeros, so 100! ends in exactly twenty-four zeros without computing the 158-digit number at all.

Computing Factorials in Code

A recursive version reads cleanly but adds a call-stack frame per step and can overflow the stack for large n. An iterative loop uses constant space and is what this tool runs under the hood, paired with BigInt so the digits never round off.

function factorial(n) {
  let result = 1n;          // BigInt keeps every digit exact
  for (let i = 2n; i <= BigInt(n); i++) {
    result *= i;
  }
  return result;            // native Number would lose precision past 2^53
}

Frequently Asked Questions

Calculators
QUICK LINKS
Contact Us
universalcalculators@gmail.com
Follow Us

Last reviewed June 2026. Our calculators and explanations are researched, built, and maintained by Jay Vaghani and the Universal Calculators team and are provided for general informational and educational purposes only. They are not professional financial, medical, or legal advice — for important decisions, please consult a qualified professional. Learn more on our About page.