# Factorial Calculator

Calculate factorials (n!), permutations (nPr), and combinations (nCr) instantly. Free online factorial calculator for math, probability, and statistics.

## What this calculates

Calculate the factorial of any integer from 0 to 170, along with permutations and combinations. Essential for probability, combinatorics, and statistical calculations.

## Inputs

- **Number (n)** — min 0, max 170 — The number to compute the factorial of (max 170 for JavaScript precision).
- **R (for permutations/combinations)** — Used for nPr and nCr calculations. Must be <= n.

## Outputs

- **n!** — formatted as text — The factorial of n.
- **nPr (Permutations)** — formatted as text — The number of r-permutations of n items: n! / (n-r)!
- **nCr (Combinations)** — formatted as text — The number of r-combinations of n items: n! / (r!(n-r)!)
- **Number of Digits in n!** — How many digits are in the factorial.

## Details

The factorial of a non-negative integer n, written n!, is the product of all positive integers from 1 to n. By definition, 0! = 1.

Factorial Formula

n! = n x (n-1) x (n-2) x ... x 2 x 1

For example: 5! = 5 x 4 x 3 x 2 x 1 = 120.

Permutations and Combinations

- Permutations (nPr): The number of ways to arrange r items from n distinct items, where order matters: nPr = n! / (n-r)!

- Combinations (nCr): The number of ways to choose r items from n distinct items, where order does not matter: nCr = n! / (r!(n-r)!)

Growth Rate

Factorials grow extremely fast. 10! = 3,628,800; 20! = 2,432,902,008,176,640,000. This rapid growth is why factorials are central to Big O analysis in computer science and why brute-force algorithms become infeasible quickly.

## Frequently Asked Questions

**Q: What is a factorial?**

A: A factorial, written n!, is the product of all positive integers up to n. For example, 5! = 5 x 4 x 3 x 2 x 1 = 120. By convention, 0! = 1. Factorials count the number of ways to arrange n distinct objects in a sequence (there are n! different permutations).

**Q: Why does 0! equal 1?**

A: The convention 0! = 1 is mathematically necessary for consistency. There is exactly one way to arrange zero objects: do nothing. It also ensures formulas like nCr = n! / (r!(n-r)!) work correctly when r = 0 or r = n. Additionally, the recurrence n! = n x (n-1)! requires 0! = 1 for the case n = 1.

**Q: What is the difference between permutations and combinations?**

A: Permutations count arrangements where order matters: how many ways can you arrange r items from n? (nPr = n!/(n-r)!). Combinations count selections where order does not matter: how many ways can you choose r items from n? (nCr = n!/(r!(n-r)!)). For example, from {A,B,C}: permutations of 2 are AB, BA, AC, CA, BC, CB (6), but combinations of 2 are AB, AC, BC (3).

**Q: How fast do factorials grow?**

A: Factorials grow faster than exponentials. While 2^10 = 1,024, we have 10! = 3,628,800. At n = 20, the factorial has 19 digits. At n = 100, it has 158 digits. Stirling's approximation, n! is approximately sqrt(2 x pi x n) x (n/e)^n, helps estimate large factorials.

**Q: What is the gamma function?**

A: The gamma function extends factorials to non-integer and complex numbers. For positive integers, gamma(n) = (n-1)!. For example, gamma(5) = 4! = 24. It satisfies gamma(n+1) = n x gamma(n). Notably, gamma(1/2) = sqrt(pi), connecting factorials to pi. The gamma function is crucial in probability distributions and advanced mathematics.

---

Source: https://vastcalc.com/calculators/math/factorial
Category: Math
Last updated: 2026-04-21
