# Factorial Calculator

- **URL:** https://codeasystem.com/calculators/math/factorial-calculator/
- **Category:** math
- **Description:** Compute n! for any whole number from 0 to 170, with digit counts and scientific magnitude shown for the huge results.
- **Primary output:** 5!: 120

## Inputs
- n (whole number, 0–170) (name: `n`, type: number, example: 5)

## Outputs
- 5!: 120
- Approximate magnitude: 10^2.08
- Digits: 3

## Formula / methodology
```
n! = n × (n−1) × … × 2 × 1     with 0! = 1 by definition
```

Direct iterative multiplication computes the product exactly as doubles allow. JavaScript numbers overflow past 170! (about 7.3×10³⁰⁶), so that ceiling is enforced with a clear message; negative and non-integer inputs are rejected because the factorial is only defined on whole numbers.

## Assumptions & limitations
- Only whole numbers 0 through 170 are accepted.
- Results beyond about 21 digits carry double-precision rounding in their trailing digits.
- 0! equals 1 by mathematical convention.

## How to use
1. **Enter a whole number**; Between 0 and 170 inclusive.
2. **Read the factorial**; The full product appears grouped with thousands separators.
3. **Check magnitude rows**; Digit count and power-of-ten size help compare enormous results at a glance.

## Example
5! = 5 × 4 × 3 × 2 × 1 = 120; the number of ways to arrange five distinct items in order.

Result for these inputs:

```
5!: 120
```

## About this calculator
### How fast factorials explode

A deck of cards can be shuffled 52! ≈ 8×10⁶⁷ ways; more than atoms in the galaxy. Ten items already offer 3.6 million orderings, which is why brute-force search dies quickly and combinatorics needs smarter tools.

### Why 0! equals 1

The empty product is conventionally 1: there is exactly one way to arrange zero objects. This convention keeps permutation formulas like nPr = n!/(n−r)! working cleanly at the boundaries instead of special-casing them.

### The 170 ceiling

Computers store numbers as floating-point values capped near 1.8×10³⁰⁸. Since 171! overflows that envelope, the calculator refuses rather than returning Infinity; honest failure beats silent nonsense.

## FAQs
### Why does 171 fail?

It exceeds the largest value a double-precision float can hold (~1.8×10³⁰⁸); 170! is the last representable factorial.

### Can I compute 4.5 factorial?

No; plain factorials need whole numbers. The generalized gamma function extends the idea, but it is outside this tool’s scope.

### Is 0! really 1?

Yes, by definition of the empty product; it keeps counting formulas consistent at zero items.

### Are the huge results exact?

Up to roughly 20! yes; larger products keep about fifteen significant digits, so trailing digits may round.

## Related calculators
- [GCD & LCM Calculator](https://codeasystem.com/calculators/math/gcd-lcm-calculator/)
- [Random Number Generator](https://codeasystem.com/calculators/math/random-number-generator/)
- [Exponent & Root Calculator](https://codeasystem.com/calculators/math/exponent-root-calculator/)

---
Last updated: 2026-08-23 · Version: 1.0.0 · [HTML version](https://codeasystem.com/calculators/math/factorial-calculator/)
