Home › Math › 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
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
n | integer | yes | Non-negative integer up to 170. Range: ≥ 0, ≤ 170 |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
factorial | number | The factorial. Exact up to 22!; above that correct to about 16 significant digits. | |
digits | integer | Decimal digits of n!: ⌊log10(n!)⌋ + 1. | |
trailing_zeros | integer | Zeros at the end of n! (Legendre's formula: ⌊n/5⌋ + ⌊n/25⌋ + …). | |
scientific_notation | string | n! 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
- API:
GET https://tttkmbb.com/api/v1/calculate/factorial(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/factorial · Markdown: https://tttkmbb.com/math/factorial.md · JSON definition: https://tttkmbb.com/math/factorial.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="factorial" - OpenAPI operationId:
calculate_factorial - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
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
- Combinations and Permutations Calculator — Counts of selections and arrangements built from factorials.
- Exponent Calculator — Powers, the other fast-growing product.