Factorial trailing zeros
100! ends in 24 zeros: 100 holds 20 fives and 4 twenty-fives, and 20 + 4 = 24. Enter a non-negative whole number to get the count of trailing zeros of its factorial, with each step shown. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 100
- Trailing zeros
- 24
The trailing zeros of a factorial are the zeros at the end of the decimal expansion of n!. Computing n! itself becomes impractical long before the zero count does: twenty-five factorial already ends with six zeros, and one hundred factorial ends with twenty-four. The standard number-theory shortcut never multiplies the whole product. It counts how many times five divides the product by adding floor of n over five, over twenty-five, over one hundred twenty-five, and so on. Because factors of two always outnumber factors of five in n!, that sum is exactly the trailing-zero count. This calculator implements that deterministic sum for any non-negative integer n, returns the total, and lists each power-of-five contribution for verification. Negative n is rejected with an input error and is not charged.
Why trailing zeros of n! equal the number of factors of five
Write n factorial as the product of every positive integer up to n. In base ten, each trailing zero is created by a factor of ten, and each ten is a factor pair of two and five. In the prime factorization of n!, the exponent of two is always at least as large as the exponent of five, so the number of complete tens is limited by the scarcer prime.
The exponent of five is the sum, over every positive integer k, of the number of multiples of five to the power k that are at most n. That quantity is floor of n divided by five to the k. Summing those floors is therefore the trailing-zero count.
Classic checks match the formula: five factorial is one hundred twenty and has one zero; ten factorial is three million six hundred twenty-eight thousand eight hundred and has two zeros; twenty-five factorial contributes floor of twenty-five over five plus floor of twenty-five over twenty-five, which is five plus one equals six. Zero factorial and one factorial are both one, so they contribute zero trailing zeros. The same identity appears in programming contest problems, interview warm-ups, and textbook exercises on de Polignac's formula for the exponent of a prime in n!.
Understanding the power-of-five sum also clarifies related questions such as the last non-zero digit of n! or the trailing zeros of binomial coefficients, both of which start from the same prime-exponent bookkeeping.
How this calculator evaluates the power-of-five sum
Call the capability with a field n holding a non-negative integer. The implementation validates that n is present, finite, integral, and not negative, then initializes a running total and a power starting at five. While the current power is at most n, it adds floor of n divided by that power to the total, records the power and the floor contribution in an audit list, and multiplies the power by five for the next term.
The loop ends when the next power would exceed n or would overflow the safe integer range, which is far beyond ordinary classroom and contest inputs. No factorial product is ever materialised, no floating-point approximation is used for the divisions, and no external arithmetic service is consulted.
What you can do with it
Homework and contest verification
Students and graders can confirm how many trailing zeros n! has for arbitrary non-negative n and inspect each floor(n/5^k) term without expanding the factorial.
Prime-exponent teaching materials
Lesson plans that introduce de Polignac's formula can show the power-of-five sum beside the trailing-zero answer so learners connect factors of five to decimal zeros.
FAQ
What happens if n is negative?
Factorial trailing zeros are defined here for non-negative integers only; negatives are rejected and not charged.
Why only powers of five and not powers of two?
Each trailing zero needs a factor of ten, which is two times five. In n! there are always at least as many factors of two as of five, so the five-exponent alone determines the zero count.
Is the factorial trailing zeros calculator free?
The browser tool runs free on your device.
Does this return the value of n! itself?
No. It only returns how many zeros end the decimal writing of n!. That keeps the computation O(log n) and exact for large n where materialising n! would be impractical.
How many trailing zeros does 100 factorial have?
It has 24. Dividing 100 by 5 gives 20, dividing it by 25 gives 4, and higher powers of five are larger than 100, so the total is 20 + 4 = 24.
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/numth/trailing-zeros-factorial \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":100}'const res = await fetch("https://api.kit.forhosting.com/numth/trailing-zeros-factorial", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 100
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/trailing-zeros-factorial",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 100
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/trailing-zeros-factorial", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":100}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":100}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/trailing-zeros-factorial", 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": 100
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.trailing_zeros_factorial",
"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.
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
How this calculator evaluates the power-of-five sum
The response returns the original n, the trailing_zeros total, and the ordered powers array so you can recompute the sum by hand. Negative inputs, non-integers, missing n, and values outside the safe integer range fail with invalid_input and are not charged.
Practical use, limits, pricing, and delivery
Use the browser tool when you need a quick trailing-zero check while solving a homework set, verifying a contest sample, or explaining prime exponents without installing a computer-algebra system. Accepted inputs are non-negative integers within the safe integer range, which already covers every standard interview and olympiad example. There is no language model, no remote calculator, and no randomness, so the capability is safe to pin in automated tests and reproducible notebooks. Each successful request is one billable item at $0.002; failed validation does not consume balance. Results are fully deterministic: the same n always yields the same trailing_zeros count and the same ordered list of power contributions. Wire the endpoint into number-theory demos, algorithm courses that introduce de Polignac's formula, interview prep pages, or integer preprocessing steps where you already trust exact integer arithmetic more than approximate heuristics or opaque black-box factorial expanders that blow up memory for large n.
Integration use cases
Automated number-theory pipelines
Scripts that classify factorials by trailing zeros or generate quiz answers can call a single deterministic item-priced endpoint instead of embedding ad hoc loops.
Technical questions
How do I count trailing zeros of n! with this API?
Send a JSON body with non-negative integer field n to the numth.trailing_zeros_factorial capability. The response returns trailing_zeros and the ordered list of power-of-five floor contributions.