GAMMALN returns the natural logarithm of the gamma function for a given number. It is useful for calculating very large factorials and gamma values without overflow errors.
=GAMMALN(x)What does GAMMALN do?
GAMMALN is a Statistical function that calculates the natural logarithm of the gamma function, written as ln(Γ(x)). The gamma function extends the idea of a factorial to non-integer numbers: for a positive whole number n, Γ(n) equals (n−1)!. Because gamma values grow extremely fast, taking the logarithm first keeps results manageable and avoids overflow errors in Excel.
You will reach for GAMMALN when you need to work with factorials of large numbers, probabilities from gamma or chi-square distributions, or any calculation where the raw gamma value would be too large to store. Instead of computing a huge number and then taking its log, GAMMALN gives you the log directly, which is far more stable.
A typical situation is a quality-control analyst modelling waiting times with a gamma distribution. The probability density formula contains a gamma function in the denominator; using GAMMALN lets the analyst compute the log-density safely, even when the shape parameter is large. Students meeting the gamma function in statistics courses also use GAMMALN to check factorial-related results quickly in a spreadsheet.
When to use GAMMALN
- Computing log-factorials for large n in probability calculations.
- Evaluating gamma-distribution densities or likelihoods without overflow.
- Working with chi-square or beta distribution formulas that involve gamma functions.
- Checking statistical results that use the gamma function in coursework.
- Modelling waiting times or reliability data with gamma-based formulas.
- Converting between gamma values and their natural logs in data analysis.
GAMMALN syntax
=GAMMALN(x)| Argument | Required? | What to enter |
|---|---|---|
x | Required | The positive number for which you want the natural logarithm of the gamma function. It must be greater than zero; for example, =GAMMALN(5) returns about 3.178. |
What it returns: GAMMALN returns a numeric value: the natural logarithm of the gamma function evaluated at x. For positive integers n, this equals ln((n−1)!).
GAMMALN examples
1 Example 2: Log factorial for a larger number
Here the goal is to compute the natural log of 9! using GAMMALN. For a whole number n, GAMMALN(n+1) equals ln(n!). Cell B2 holds 10, so =GAMMALN(B2) returns ln(9!) = ln(362880). The expected result is about 12.80182748. This approach avoids typing the factorial itself and works for much larger n than FACT can handle.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | n | n+1 | Log factorial | |||
| 2 | 9 | 10 | 12.80182748 | |||
| 3 | 5 | 6 | ||||
| 4 | 3 | 4 | ||||
| 5 |
2 Example 3: Gamma density component for waiting times
A support team models waiting times with a gamma distribution whose shape parameter is in column B. The density formula includes Γ(shape) in the denominator, so the log-density uses −GAMMALN(shape). The goal is to compute that log-gamma component for the first ticket type. With shape 3 in B2, =-GAMMALN(B2) returns −ln(2!) = −ln(2), about −0.69314718. This keeps the calculation stable for larger shape values.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Ticket type | Shape | Scale | |||
| 2 | Password reset | 3 | 2.5 | -0.6931471806 | ||
| 3 | Software install | 4 | 1.8 | |||
| 4 | Network issue | 2 | 3.2 | |||
| 5 |
3 Example 4: Log of a gamma ratio for a likelihood
This example compares two gamma shape parameters in a simple likelihood ratio. The goal is to compute ln(Γ(shape1)) − ln(Γ(shape2)) using GAMMALN for the first product category. Cell B2 holds 6 and C2 holds 4, so =GAMMALN(B2)-GAMMALN(C2) returns ln(5!) − ln(3!) = ln(120) − ln(6) = ln(20). The expected value is about 2.99573227, which is the log of the ratio of the two gamma values.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Product | Shape 1 | Shape 2 | |||
| 2 | Widget A | 6 | 4 | 2.995732274 | ||
| 3 | Widget B | 8 | 5 | |||
| 4 | Widget C | 3 | 2 | |||
| 5 |
4 Example 5: Sum of log-gamma terms across rows
A student checks a statistical formula that sums log-gamma terms for several parameter values. The goal is to add GAMMALN for the three shape values in column B. The formula =GAMMALN(B2)+GAMMALN(B3)+GAMMALN(B4) evaluates each term and adds them. With shapes 2, 3 and 4, the result is ln(1) + ln(2) + ln(6) = 0 + 0.69314718 + 1.79175947, about 2.48490665. This mirrors how log-likelihoods are built from separate gamma components.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Parameter | Shape | |||
| 2 | Alpha | 2 | 2.48490665 | ||
| 3 | Beta | 3 | |||
| 4 | Gamma | 4 | |||
| 5 |
Common GAMMALN errors and how to fix them
| Error | Why it happens | How to fix it |
|---|---|---|
| #NUM! | The argument x is zero or negative, where the gamma function is undefined or not finite. | Supply a positive number greater than zero; check the source cell for zero or negative values. |
| #VALUE! | The argument is text that cannot be interpreted as a number. | Reference a numeric cell or enter a number directly; remove stray text or spaces. |
| #NAME? | The function name is misspelled, for example GAMMALN typed without the final N or with extra characters. | Use the exact spelling GAMMALN and let Excel's formula AutoComplete help you. |
| #DIV/0! | A surrounding formula divides by the GAMMALN result when that result is zero, which happens at x = 1 because ln(Γ(1)) = ln(1) = 0. | Guard the division with IFERROR or check that x is not 1 before dividing. |
Tips for using GAMMALN
- Remember that GAMMALN(n) equals ln((n−1)!) for positive whole numbers, so GAMMALN(6) gives ln(120).
- Use GAMMALN instead of LN(FACT(n)) for large n to avoid overflow errors.
- To get the gamma value itself, wrap the result in EXP:
=EXP(GAMMALN(x)). - Keep arguments positive; zero and negative numbers return #NUM!.
- Combine GAMMALN with SUM or SUMPRODUCT to add log-gamma terms across many rows.
- For log-factorials, GAMMALN(n+1) is the direct route: it returns ln(n!).
Frequently asked questions
What is the difference between GAMMALN and GAMMA?
GAMMALN returns the natural logarithm of the gamma function, while GAMMA returns the gamma function value itself. Use GAMMALN when the gamma value would be very large.
Can GAMMALN handle zero or negative numbers?
No. GAMMALN requires a positive number; zero or negative arguments return the #NUM! error.
How do I get a factorial using GAMMALN?
For a whole number n, use =EXP(GAMMALN(n+1)) to get n!, or =GAMMALN(n+1) to get ln(n!).
Why does GAMMALN(1) return 0?
Because Γ(1) = 1 and the natural logarithm of 1 is 0. This is a correct result, not an error.
Is GAMMALN available in all Excel versions?
Yes, GAMMALN is built into Excel and has been available since before Excel 2007.
Related functions
Every example on this page was recalculated by SheetSkill’s spreadsheet engine. GAMMALN reference