Written and maintained by CASRAI Editorial Board
Last updated
A moving average replaces each value in a series with the mean of a small window of neighbouring values, which smooths out short-term noise so a trend is easier to see. This guide gives the definition, the trailing and centred formulas, a fully worked example, how to read the result and how to compute it in Excel, R and Python.
What is a moving average? Definition in one paragraph
A moving average is the mean of a fixed number of consecutive observations, recalculated as the window slides along the series one period at a time. The NIST/SEMATECH e-Handbook of Statistical Methods puts it directly: “Taking a moving average is a smoothing process.” Each new average moves forward one period and drops the oldest value from the window. The number of values averaged is the window size (also called the order or span). A larger order gives a smoother curve (Hyndman and Athanasopoulos, 2021).
Moving average formula: trailing and centred
Two forms are in common use, and they answer slightly different questions. Mixing them up is the most frequent source of confusion, so both are shown side by side.
Trailing (single) moving average
The NIST handbook defines the single moving average using only the current and past values:
Mt = (Xt + Xt-1 + … + Xt-N+1) / N
- Mt: the moving average at period t.
- Xt: the observed value at period t.
- N: the number of values in each average (the window size). This page uses N; the NIST page uses a different letter for the same quantity.
- t: the current period.
Centred moving average (m-MA)
In Forecasting: Principles and Practice, Hyndman and Athanasopoulos estimate the trend-cycle at time t by averaging k values on each side of it:
T̂t = (1/m) ∑ yt+j, for j = -k, …, k, where m = 2k + 1
- T̂t: the smoothed estimate at time t.
- yt+j: the observation j periods away from t.
- m: the order, always odd in this form; the authors call it “a moving average of order m” or an m-MA.
- k: how many observations are taken on each side.
For an even order the same source uses a two-step average, such as a 2×4-MA, called a centred moving average of order 4. It is equivalent to a weighted 5-term average with weights 1/8, 1/4, 1/4, 1/4 and 1/8.
Moving average example: worked arithmetic
The NIST handbook illustrates the method with a series of 12 supplier dollar amounts, which are treated here as 12 consecutive periods: 9, 8, 9, 12, 9, 12, 11, 7, 13, 9, 11, 10. Using a window of N = 3, each average is the sum of the latest three values divided by 3.
| Period t | Value Xt | Window | Sum | 3-period trailing average |
|---|---|---|---|---|
| 1 | 9 | – | – | – |
| 2 | 8 | – | – | – |
| 3 | 9 | 9, 8, 9 | 26 | 8.667 |
| 4 | 12 | 8, 9, 12 | 29 | 9.667 |
| 5 | 9 | 9, 12, 9 | 30 | 10.000 |
| 6 | 12 | 12, 9, 12 | 33 | 11.000 |
| 7 | 11 | 9, 12, 11 | 32 | 10.667 |
| 8 | 7 | 12, 11, 7 | 30 | 10.000 |
| 9 | 13 | 11, 7, 13 | 31 | 10.333 |
| 10 | 9 | 7, 13, 9 | 29 | 9.667 |
| 11 | 11 | 13, 9, 11 | 33 | 11.000 |
| 12 | 10 | 9, 11, 10 | 30 | 10.000 |
The first average is (9 + 8 + 9) / 3 = 8.667, the second is (8 + 9 + 12) / 3 = 9.667, and the third is (9 + 12 + 9) / 3 = 10.000, matching the values printed in the NIST example. The raw series swings between 7 and 13; the 3-period averages stay between 8.667 and 11.000.
The same data with a centred 5-MA
With m = 5 (k = 2), each smoothed value is the mean of the value itself, two before and two after. At period 3 that is (9 + 8 + 9 + 12 + 9) / 5 = 47 / 5 = 9.4. Working through periods 3 to 10 gives 9.4, 10.0, 10.6, 10.2, 10.4, 10.4, 10.2 and 10.0. The range narrows to 9.4 to 10.6, which shows the “larger order, smoother curve” rule on real numbers. The cost is visible too: the first two and last two periods have no 5-MA value, matching the end-point gaps in Table 3.1 of Hyndman and Athanasopoulos.
How to interpret a moving average
Read the smoothed line as an estimate of the underlying level or trend, not as the data itself. Compare the row guidance below with the worked example above.
| What you see | How to read it | Basis |
|---|---|---|
| Larger window | Smoother curve; short-term movement is averaged away | Hyndman and Athanasopoulos: “a larger order means a smoother curve” |
| Trailing average, N = 3, period 4 = 9.667 | Mean of periods 2 to 4; its window is centred on period 3, so it sits half a window behind the latest value | Arithmetic from the NIST formula |
| Centred 5-MA, period 3 = 9.4 | Mean of periods 1 to 5, aligned with the middle period | Hyndman and Athanasopoulos formula |
| Missing values at the ends | Trailing N-window loses the first N – 1 values; a centred m-MA loses k values at each end | 3-MA gives 10 averages from 12 values; 5-MA gives 8 |
Assumptions and common mistakes
- Treating a trailing and a centred average as interchangeable. The trailing form uses only past values; the centred form uses values on both sides, so it cannot be computed for the most recent periods. State which one you used.
- Plotting a trailing average at the wrong period. A 3-period trailing average is the mean of periods 2 to 4 when t = 4, but its window is centred on period 3. Plot it at t only if you mean “average of the latest N”.
- Forgetting the lost end points. A centred m-MA has no value for the first and last k periods; a trailing N-window has none for the first N – 1.
- Using an even order without centring. A plain 4-period window has no middle observation. Hyndman and Athanasopoulos use the 2×4-MA, whose weights are 1/8, 1/4, 1/4, 1/4 and 1/8.
- Using it on an unordered series. The window assumes observations are in time or sequence order. For serial dependence between observations see autocorrelation in time-series data.
How to report a moving average
State the type (trailing or centred), the window size, the unit of the periods and how the end points were handled. An illustrative sentence for a methods section:
Weekly counts were smoothed with a centred 5-period moving average (k = 2); the first and last two weeks have no smoothed value and are omitted from the figure.
An APA-style reference for the formula source used on this page:
Hyndman, R. J., & Athanasopoulos, G. (2021). Forecasting: Principles and practice (3rd ed.). OTexts. https://otexts.com/fpp3/
How to calculate a moving average in Excel, R or Python
Each snippet uses the twelve values above (period 1 in row 2 for Excel).
Excel
Trailing 3-period (put in D4, fill down to D13):
=AVERAGE(B2:B4)
Centred 5-period (put in F4 for period 3, fill down to F11):
=AVERAGE(B2:B6)
R
x <- c(9, 8, 9, 12, 9, 12, 11, 7, 13, 9, 11, 10)
stats::filter(x, rep(1/3, 3), sides = 1) # trailing, first 2 are NA
stats::filter(x, rep(1/5, 5), sides = 2) # centred, 2 NA at each end
Python (pandas)
import pandas as pd
x = pd.Series([9, 8, 9, 12, 9, 12, 11, 7, 13, 9, 11, 10])
x.rolling(window=3).mean() # trailing
x.rolling(window=5, center=True).mean() # centred
Both languages return missing values at the ends, matching the gaps in the table. For forecasting models that build on smoothing, see ARIMA models for research time series, and for a before-and-after design on a series see interrupted time-series analysis. To describe the spread of the raw values, see descriptive statistics and standard deviation.
Frequently asked questions
What is a moving average?
A moving average is the mean of a fixed-size window of consecutive observations, recalculated as the window moves one period at a time. It is a smoothing process that reduces short-term variation so a trend is easier to read.
What is the moving average formula?
For a trailing average, Mt = (Xt + Xt-1 + … + Xt-N+1) / N. For a centred average of odd order m = 2k + 1, the estimate at t is the sum of yt+j for j from -k to k, divided by m.
What are some moving average examples?
With the series 9, 8, 9, 12, 9 and N = 3, the first three trailing averages are 8.667, 9.667 and 10.000. A centred 5-period average at period 3 of the same series gives 9.4.
Does a bigger window smooth more?
Yes. Hyndman and Athanasopoulos state that in general a larger order means a smoother curve. In the example above the 3-period averages range from 8.667 to 11.000 and the centred 5-period averages from 9.4 to 10.6.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods, section 6.4.2.1 “Single Moving Average”: itl.nist.gov/div898/handbook/pmc/section4/pmc421.htm (checked 29 October 2026).
- Hyndman, R. J., & Athanasopoulos, G. Forecasting: Principles and Practice, 3rd edition, section 3.3 “Moving averages”: otexts.com/fpp3/moving-averages.html (checked 29 October 2026).








