Skip to main content
v2026.11,858 entries · CC-BY 4.0

Log Transformation Formula: Definition and Worked Example

The log transformation formula y = ln(x) explained: symbols, a worked example with arithmetic, APA reporting, and Excel, R and Python code.

Written and maintained by CASRAI Editorial Board

Last updated

The log transformation formula replaces every value x in a dataset with its logarithm, y = ln(x) (or y = log10(x)). It only works for positive values, and it turns multiplicative differences into additive ones. This page gives the formula with every symbol explained, a six-value worked example with the arithmetic shown, reporting wording and short Excel, R and Python snippets. For the wider question of when to transform at all, see log and other data transformations.

What is a log transformation?

A log transformation applies a logarithm to each observation and then analyses the transformed numbers instead of the originals. It is used mainly on positive, right-skewed data (a long tail of large values), so that the transformed values sit closer to a symmetric, roughly normal shape. The NIST/SEMATECH e-Handbook notes that an appropriate transformation of a data set can often yield a data set that does follow approximately a normal distribution. The same handbook shows that the natural log is the special case lambda = 0 of the Box-Cox family.

Log transformation formula

yi = ln(xi), for every xi > 0. The base-10 version is yi = log10(xi).

  • xi: the i-th original observation. It must be strictly greater than zero.
  • yi: the transformed value that you analyse.
  • ln: the natural logarithm, the logarithm to base e (e is about 2.71828). It is the inverse of exp, so ln(exp(x)) = x.
  • log10: the logarithm to base 10. Because log10(x) = ln(x) / ln(10), and ln(10) is about 2.3026, the two choices differ only by a constant factor.
  • Back-transform: x = exp(y) for the natural log, or x = 10y for base 10.

The NIST handbook gives the Box-Cox transformation as T(Y) = (Yλ − 1) / λ and states that for λ = 0 the natural log of the data is taken instead of using that formula. The log is therefore one member of a larger power-transformation family, not a separate technique.

Why use a log transformation?

Three reasons come up most often, and each follows from the formula rather than from convention.

  • Skewed data become more symmetric. Large values are pulled in much more than small ones, which shortens a long right tail.
  • Ratios become differences. Because ln(a) − ln(b) = ln(a / b), a constant percentage change is a constant step on the log scale. That suits growth, concentrations and counts that vary by multiples.
  • Spread that grows with the mean can be stabilised. When variability rises in proportion to the level, taking logs tends to make the spread more even, which many models assume.

If the original data are themselves described by a lognormal distribution, the logs are normally distributed by definition.

Worked example with the arithmetic

Take six positive measurements, in the original units: 5, 12, 20, 45, 110 and 300. The arithmetic mean is (5 + 12 + 20 + 45 + 110 + 300) / 6 = 492 / 6 = 82.0, which is larger than five of the six values because 300 pulls it up.

x ln(x) log10(x)
5 1.6094 0.6990
12 2.4849 1.0792
20 2.9957 1.3010
45 3.8067 1.6532
110 4.7005 2.0414
300 5.7038 2.4771
  1. Sum of the natural logs: 1.6094 + 2.4849 + 2.9957 + 3.8067 + 4.7005 + 5.7038 = 21.3010.
  2. Mean of the logs: 21.3010 / 6 = 3.5502.
  3. Standard deviation of the logs (n − 1 in the denominator): 1.4990.
  4. Back-transform the mean: exp(3.5502) = 34.8. This is the geometric mean, not the arithmetic mean of 82.0.
  5. Ratios become differences: 300 / 5 = 60, and ln(300) − ln(5) = 5.7038 − 1.6094 = 4.0944 = ln(60).

The skewness (third standardised moment, computed over all six values) falls from 1.39 on the raw scale to 0.18 on the log scale, so the transformed values are far more symmetric. With six points that is an illustration of the mechanics, not evidence about a population; check real data with a Q-Q plot and a formal test such as the Shapiro-Wilk test in R.

Interpretation: reading results on the log scale

What you see How to read it
Mean of the ln values (3.5502) exp(3.5502) = 34.8 is the geometric mean in original units.
Difference of 0.6931 between two ln values The larger value is twice the smaller, since ln(2) = 0.6931.
Difference of 2.3026 between two ln values The larger value is ten times the smaller, since ln(10) = 2.3026.
Difference of 1 between two log10 values The larger value is ten times the smaller.
95% interval on the log scale, 1.98 to 5.12 (t with 5 df, 2.571 × 1.4990 / √6 = 1.57) Back-transformed, 7.2 to 167.9 is an interval for the geometric mean.

Assumptions and common mistakes

  • Values must be positive. The R documentation states that log(0) gives -Inf and that the log of a negative number is NaN. NumPy’s np.log([1, np.e, np.e**2, 0]) returns [0., 1., 2., -inf]. A zero or negative value cannot simply be logged.
  • Adding a constant changes the answer. Using ln(x + c) to handle zeros makes the result depend on the arbitrary c, so state c. R offers log1p(x), which computes log(1 + x) accurately even for very small |x|. The guide on log and other data transformations covers the zero problem in detail.
  • Do not report the back-transformed mean as the mean. exp(mean of logs) is the geometric mean (34.8 here), not the arithmetic mean (82.0).
  • Mixing bases. Coefficients and differences on a ln scale and a log10 scale are not interchangeable; say which you used.
  • Transforming is not a cure for every skew. Check the transformed values, not just the originals; see the skew-normal distribution guide for a distribution family built for skewness.

How to report it (APA example)

State the transformation, its base, any constant added, and report back-transformed summaries as geometric means. For the example above:

Measurements were right-skewed (skewness = 1.39), so they were natural-log transformed before analysis. The mean of the log-transformed values was M = 3.55 (SD = 1.50), corresponding to a geometric mean of 34.8 in original units (95% CI [7.2, 167.9]).

How to calculate it in Excel, R or Python

Excel (values in A2:A7; put the first formula in B2 and fill down):

=LN(A2)
=LOG10(A2)
=EXP(AVERAGE(B2:B7))   (geometric mean, returns 34.8)

R:

x <- c(5, 12, 20, 45, 110, 300)
y <- log(x)            # natural log; log10(x) for base 10
exp(mean(y))           # geometric mean, 34.8
log1p(x)               # log(1 + x), if a constant of 1 is justified

Python:

import numpy as np
x = np.array([5, 12, 20, 45, 110, 300])
y = np.log(x)          # natural log; np.log10(x) for base 10
np.exp(y.mean())       # geometric mean, 34.8

Frequently asked questions

What is log transformation?

It is replacing each positive value x with ln(x) or log10(x) before analysis, usually to reduce right skew and to make multiplicative differences additive.

Why use log transformation?

To make skewed, positive data more symmetric, to treat ratios as differences, and to even out spread that grows with the mean, so that methods assuming approximate normality or constant variance fit better.

Which base should I use?

Either. The two differ by the constant factor ln(10), about 2.3026. Choose the one that makes results easiest to read, and state it.

Can I log-transform zero?

No. R returns -Inf for log(0) and NumPy returns -inf. Any workaround, such as adding a constant, must be reported.

Sources

Checked 2026-10-29.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Log Transformation Formula: Definition and Worked Example

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.