HomeMath › Factorial Calculator

Factorial Calculator

Computes n! = 1 × 2 × … × n for integers from 0 to 170, together with the number of decimal digits, the number of trailing zeros and a scientific-notation form.

When to use

You need the factorial of an integer, e.g. for counting arrangements or as a building block of permutations and combinations.

Do not use when: n exceeds 170 (the result overflows double precision; use Stirling's approximation or log-gamma) or you need C(n, k) / P(n, k) directly (use combinations-permutations).

Formula

n! = n × (n − 1) × … × 2 × 1, with 0! = 1; digits = ⌊Σ log10(i)⌋ + 1; trailing_zeros = Σ ⌊n / 5^k⌋

Inputs

ParameterTypeUnitRequiredDescription
nintegeryesNon-negative integer up to 170. Range: ≥ 0, ≤ 170

Outputs

OutputTypeUnitDescription
factorialnumberThe factorial. Exact up to 22!; above that correct to about 16 significant digits.
digitsintegerDecimal digits of n!: ⌊log10(n!)⌋ + 1.
trailing_zerosintegerZeros at the end of n! (Legendre's formula: ⌊n/5⌋ + ⌊n/25⌋ + …).
scientific_notationstringn! with 5 significant digits, e.g. '2.4329 × 10^18'.

Example

5!: {"n":5}{"factorial":120,"digits":3,"trailing_zeros":1,"scientific_notation":"1.2 × 10^2"}

20!: {"n":20}{"factorial":2432902008176640000,"digits":19,"trailing_zeros":4,"scientific_notation":"2.4329 × 10^18"}

GET https://tttkmbb.com/api/v1/calculate/factorial?n=5

Machine access

Sources

FAQ

Why is 0! equal to 1?

By definition (the empty product), which keeps the recurrence n! = n × (n − 1)! and the counting formulas consistent.

Is the result exact?

Up to 22! every digit is exact. From 23! on the value has more than 53 significant bits, so only the first ~16 significant digits are reliable; the digit and trailing-zero counts stay exact.

Related calculators