Factorial calculator
5! is 120 and 10! is 3628800. Enter a whole number from 0 to 5000 and get its exact factorial with every digit, never a rounded or approximate value, ready for permutations, combinations and probability homework. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 5
- Value
- 120
- Product
- 120
Factorial is the product of all positive integers up to n, written n! and defined for every non-negative integer, with the empty product convention that zero factorial equals one. It appears in permutations, combinations, Taylor series, probability models, and countless programming exercises where the answer must be exact rather than approximate. This calculator accepts a non-negative integer n and returns the exact factorial as a decimal string computed with BigInt arithmetic, so values far beyond ordinary floating-point or safe-integer limits stay correct digit for digit. Negative inputs and non-integers are rejected with a clear validation error rather than a silent wrong answer or a rounded approximation.
How n factorial is defined and computed
The factorial of a non-negative integer n is the product of all positive integers from one through n. By definition the empty product for n equals zero is one, so zero factorial is one and one factorial is also one.
The sequence continues two factorial equals two, three factorial equals six, four factorial equals twenty-four, five factorial equals one hundred twenty, six factorial equals seven hundred twenty, ten factorial equals three million six hundred twenty-eight thousand eight hundred, and growth is super-exponential in the sense that each step multiplies by a larger factor. This implementation never uses floating-point approximation, Stirling shortcuts, or gamma-function libraries: it starts from product one and multiplies successive integers from two through n using BigInt so every intermediate and final digit is integer-exact.
The path is fully deterministic—no random seeds, no clocks, no network, and no model drift—so the same n always yields the same string.
Where exact factorials show up in real work
Probability and combinatorics educators need n! when counting permutations of n distinct objects, when building binomial coefficients as n! over k! times (n minus k)!, and when illustrating how fast counting functions grow on slides and answer keys.
Scientific and engineering code often needs exact small-to-medium factorials for series coefficients, discrete distributions, or sanity checks against libraries that switch to floating point too early; an exact string check confirms implementations before precision bugs hide in larger systems. Product demos and interview prep often show a short factorial table; computing n! in one call keeps interactive demos aligned with textbooks.
If you later need double factorial, multifactorial, subfactorial, or the gamma function for non-integer arguments, treat those as separate search intents rather than overloading this calculator landing.
What you can do with it
Teaching permutations and growth
Show students the factorial sequence as exact strings so large terms stay correct and 0!=1 through 10!=3628800 matches textbook tables.
Library and DP sanity checks
Confirm factorial helpers, binomial intermediates, or series coefficients against a trusted BigInt product before shipping numeric code.
FAQ
What is n factorial?
n! is the product 1×2×…×n for a non-negative integer n, with 0! defined as 1. This tool returns that exact product as a decimal string.
Why is the product a string instead of a number?
Factorials grow past JavaScript safe integers by 21!. Decimal strings keep every digit exact for large n.
What happens if n is negative or not an integer?
Factorial here is defined only for non-negative integers; negatives and decimals are rejected.
Is 0! allowed?
Yes. Zero factorial equals 1 under the standard empty-product definition. Only negative n and non-integers are rejected.
What does it cost?
The browser tool is free and runs locally.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/factorial-calculator \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5}'const res = await fetch("https://api.kit.forhosting.com/math/factorial-calculator", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 5
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/factorial-calculator",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 5
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/factorial-calculator", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":5}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":5}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/factorial-calculator", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 5
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.factorial_calculator",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
min_n | 0 |
max_n | 5000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The free browser tool and the paid API share one pure function, so homework demos and automated pipelines never silently diverge on the same n.
How n factorial is defined and computed
Returning the product as a decimal string keeps JSON consumers honest: factorials leave the safe-integer range of ordinary JavaScript numbers by twenty-one factorial, and a numeric type would silently round. Bounds keep n between zero and five thousand so worst-case latency stays suitable for a free in-browser tool and a lightweight Worker path, while still covering contest, classroom, and pipeline needs for exact large products.
What you send and what you get back
The error for negative n states that factorial is defined for non-negative integers so form clients and scripts can correct the input without guessing. On success the response always includes the normalized n together with product and value as the exact n factorial written in decimal (both fields carry the same digit string for convenience). Provide a required non-negative integer under the field n, or the aliases number or value. The value must be an integer from zero through five thousand inclusive; missing fields, non-integers, decimals, and any n below zero are rejected with invalid_input and are not charged. Example checks: n equals zero yields product one; n equals one yields product one; n equals five yields product one hundred twenty; n equals ten yields product three million six hundred twenty-eight thousand eight hundred; n equals negative one yields invalid_input; n equals three point five yields invalid_input. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where exact factorials show up in real work
Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.
Integration use cases
Contest and homework fixtures
Generate exact n! decimal strings for olympiad problems, programming exercises, and automated answer keys that reject floating-point drift.