Factorial Calculator

Calculate n! for any non-negative integer. n! = n×(n-1)×⋯×1. Essential for combinations, permutations, and probability. Supports simplification of n!/k!

🔢 Number Theory📐 n! = n × (n-1) × ⋯ × 2 × 1🔢 Math
Calculate n!
Simplify: also enter k to get n!/k!
Please enter valid values.

Formula & Reference

VariableSymbolFormulaUnits
Factorial Calculatorn! = n × (n-1) × ⋯ × 2 × 1integer

Understanding Factorials

For a non-negative integer n, the factorial n! is the product of every positive integer from n down to 1. Thus 6! = 6×5×4×3×2×1 = 720. The special value 0! = 1 is not arbitrary: it keeps counting formulas consistent, because there is exactly one way to arrange or choose nothing.

Factorials appear whenever order matters. If n distinct objects can be arranged in a line, there are n! possible arrangements. Partial arrangements use P(n,r)=n!/(n-r)!, while combinations use C(n,r)=n!/[r!(n-r)!]. Writing these ratios symbolically before multiplying often cancels large factors and makes the arithmetic much easier.

Growth is extremely fast. Each step from n! to (n+1)! multiplies the previous value by n+1, so factorials soon exceed ordinary numeric ranges. This calculator evaluates exact floating-point factorials only through 170!, after which standard JavaScript numbers overflow. For larger n, logarithms, arbitrary-precision integers, or approximations such as Stirling's formula are more appropriate.

Step-by-Step Examples

Example 1
5!

5!

  • 5×4×3×2×1=120
✓ 120
Example 2
10!

10!

  • = 3,628,800
✓ 3,628,800
Example 3
0!

0!=1

  • By definition; ensures C(n,0)=1
✓ 1
Example 4
8!/5!

Cancel the shared 5! factor before multiplying.

  • 8!/5! = 8×7×6
  • 8×7×6 = 336
✓ 336
Example 5
Number of arrangements of 7 objects

Seven distinct objects can be ordered in 7! ways.

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

Real-World Applications

Common Mistakes to Avoid

⚠️
0!=0 is wrong

0!=1 by definition, required for boundary cases in formulas.

⚠️
Overflow beyond 170

170! is maximum for float64. Use Stirling for larger n.

⚠️
Simplify before computing

n!/k! = product from k+1 to n. Avoids huge intermediates.

⚠️
Using factorials for non-integers without clarification

The elementary factorial n! is defined here for non-negative integers. The gamma function extends the idea to many non-integer values, but that is a different computational model.

How to Interpret and Check Factorial Results

A simple recurrence gives the fastest check: n! must equal n×(n-1)!. If you know 9! = 362,880, then 10! must be 10×362,880 = 3,628,800. A result that does not satisfy this relationship is incorrect.

For factorial ratios, cancel first. For example, 12!/10! is only 12×11 = 132; computing both enormous factorials separately adds unnecessary work and increases the chance of overflow. In probability and combinatorics, also decide whether order matters before choosing between permutations and combinations.

Because factorials are counts, ordinary factorial answers are whole non-negative integers. Decimal inputs should not be silently treated as nearby integers. When estimating very large factorials, compare orders of magnitude using logarithms or Stirling's approximation rather than expecting a conventional decimal expansion.

Another useful check comes from divisibility. For n≥2, n! must be divisible by every positive integer from 1 through n. For example, 8!=40,320 is divisible by 7, 6, 5, and the smaller positive integers. Factorials also make ratios grow predictably: (n+1)!/n! = n+1. These simple identities are often faster to verify than recomputing a long product from the beginning.

This recurrence is also a convenient unit test when implementing factorial code.

Frequently Asked Questions

What is n!?
n×(n-1)×...×1. 5!=120.
Why grows so fast?
Each step multiplies previous by n. 20!=2.4×10¹⁸.
Stirling's approximation?
n!≈√(2πn)(n/e)^n — very accurate for large n.
Permutations?
P(n,r)=n!/(n-r)!
Gamma function?
Γ(n)=(n-1)! extends factorial to non-integers.
How can I simplify n!/k!?
When n≥k, cancel k! and multiply only the integers from k+1 through n. For example, 8!/5! = 8×7×6 = 336.
When should I use factorials in counting?
Use factorials when counting arrangements of distinct items and inside permutation or combination formulas. First decide whether order matters and whether all items or only some are selected.

Related Math Calculators

Formula Explorer connections

Interpretation: This formula uses integer divisibility, modular arithmetic, finite fields or coding relationships. Assumption: Inputs are usually integers with specific modulus or coprimality requirements. Cryptographic examples are educational and not a substitute for vetted security libraries.

Finite Field GF(2ⁿ) Calculator →GCF and LCM Calculator – Greatest Common Factor and Least Common Multiple →Hamming Distance Calculator →Math Formula Explorer →