# Harmonic Mean: Formula, Examples and When to Use It

The harmonic mean is an average that divides the count of values by the sum of their reciprocals. You use it when your data are rates or ratios measured against a fixed total, such as speeds over equal distances or price-to-earnings ratios. In those cases the harmonic mean gives the correct average, while the arithmetic mean overshoots.

## Quick Answer

- The harmonic mean formula is $H = n / \sum (1/x_i)$, where $n$ is the number of values and $x_i$ are the values themselves.
- It is always less than or equal to the geometric mean, which is always less than or equal to the arithmetic mean for positive numbers.
- Use it for rates, ratios, and per-unit quantities where the numerator quantity is fixed, such as averaging speeds (km per hour) over equal distances (km).
- Do not use it when values can be zero or negative, because the reciprocal is undefined or the result becomes meaningless.
- In the worked example below, speeds of 30, 40, and 60 km/h give a harmonic mean of 40.0000 km/h, an arithmetic mean of 43.3333 km/h, and a geometric mean of 41.6017 km/h.

## The Formula

For a set of $n$ positive values $x_1, x_2, \dots, x_n$, the harmonic mean is:

$$H = \frac{n}{\frac{1}{x_1} + \frac{1}{x_2} + \dots + \frac{1}{x_n}} = \frac{n}{\sum_{i=1}^{n} \frac{1}{x_i}}$$

Each symbol means the following:

| Symbol | Meaning |
|---|---|
| $H$ | The harmonic mean |
| $n$ | The number of values in the dataset |
| $x_i$ | The $i$-th value, all positive |
| $\sum (1/x_i)$ | The sum of the reciprocals of all values |

The formula is sometimes written as the reciprocal of the arithmetic mean of the reciprocals. That is the same thing: you average the reciprocals, then flip the result back. This is why the harmonic mean is also called the harmonic average.

## How to Calculate It Step by Step

1. Confirm every value is positive and nonzero. If any value is zero, the harmonic mean is undefined.
2. Count the values to get $n$.
3. Take the reciprocal of each value, $1/x_i$.
4. Add all the reciprocals together to get $\sum (1/x_i)$.
5. Divide $n$ by that sum. The result is $H$.

For two values only, the formula simplifies to $H = 2x_1x_2 / (x_1 + x_2)$. This shortcut is handy for paired rates.

## Worked Example

The dataset is a three-leg trip where each leg covers the same 60 km distance at a different speed.

| leg | speed_kmh | distance_km | time_h |
|---|---|---|---|
| 1 | 30 | 60 | 2 |
| 2 | 40 | 60 | 1.5 |
| 3 | 60 | 60 | 1 |

The steps are:

1. Speeds (km/h): [30.0, 40.0, 60.0]
2. Reciprocals $1/v$: $1/30 + 1/40 + 1/60 = 0.0750$
3. Harmonic mean formula: $H = n / \sum(1/x) = 3 / 0.0750 = 40.0000$ km/h
4. Arithmetic mean: $(30 + 40 + 60) / 3 = 43.3333$ km/h
5. Geometric mean: $(30 \cdot 40 \cdot 60)^{1/3} = 41.6017$ km/h
6. Check via equal-distance trip: total distance 180 km / total time 4.5000 h = 40.0000 km/h

The check is the important part. Because each leg is the same distance, the true average speed is total distance divided by total time, which is 40.0000 km/h. That matches the harmonic mean exactly. The arithmetic mean of 43.3333 km/h is too high by 3.3333 km/h.

Here is the calculation in Python using the standard library:

```python
import statistics
speeds = [30.0, 40.0, 60.0]
hm = len(speeds) / sum(1/s for s in speeds)
am = statistics.mean(speeds)
gm = statistics.geometric_mean(speeds)
print(f"hm={hm:.4f}, am={am:.4f}, gm={gm:.4f}")
```

Output:

```
hm=40.0000, am=43.3333, gm=41.6017
```

The bar chart below compares the three averages for these speeds.

| Average | Value (km/h) |
|---|---|
| Arithmetic mean | 43.33 |
| Harmonic mean | 40.00 |
| Geometric mean | 41.60 |

## How to Interpret the Result

The harmonic mean answers a specific question: what single rate would produce the same total effect as the individual rates? When the quantity being averaged is a rate and the base is constant, the harmonic mean is the correct average.

The ordering $H \le G \le A$ always holds for positive values, and the gap between them grows as the values spread out. In the example the spread is moderate, so the three averages sit within about 3.3 km/h of each other. If one leg were 5 km/h and another 100 km/h, the harmonic mean would drop far below the arithmetic mean because the slow leg dominates the total time.

If you want to compare this with other central tendency measures, see the [sample mean definition and formula](/blog/data-analysis/sample-mean) and the [mean and standard deviation guide](/blog/data-analysis/mean-and-standard-deviation).

## Doing It in Software (Excel, R or Python)

In Excel, there is a dedicated function, `HARMEAN(number1, [number2], ...)`. For the speeds in cells A1 to A3, you would write `=HARMEAN(A1:A3)`, which returns 40. If you prefer to see the mechanics, `=3/SUMPRODUCT(1/A1:A3)` gives the same result.

In R, the harmonic mean is not in base R, so you compute it directly:

```r
x <- c(30, 40, 60)
n <- length(x)
hm <- n / sum(1 / x)
```

In Python, the `statistics` module has `mean`, `geometric_mean` (Python 3.8 and later) and `harmonic_mean` (Python 3.6 and later), so `statistics.harmonic_mean([30, 40, 60])` returns 40.0. The manual formula shown above works in any version. If you want to check several averages at once, the [mean, median and mode calculator](/tools/mean-median-mode-calculator) is a quick way to verify your arithmetic.

For weighted versions of averages, the [weighted arithmetic mean formula](/blog/data-analysis/weighted-arithmetic-mean-formula-examples) covers the case where each value carries a different weight. The [geometric mean definition and formula](/blog/data-analysis/geometric-mean-definition-formula) explains the middle average in the ordering.

## Common Mistakes

- **Using the harmonic mean for values that can be zero.** The reciprocal of zero is undefined, so the result breaks. Fix: check for zeros first and decide whether those observations belong in the average at all.
- **Averaging speeds with the arithmetic mean when distances are equal.** This overstates the true average speed. Fix: use the harmonic mean when the base (distance) is constant.
- **Confusing the harmonic mean with the geometric mean.** They are different formulas and give different answers. Fix: use the harmonic mean for rates whose numerator quantity is fixed, such as equal distances, and the geometric mean for multiplicative growth.
- **Forgetting that $n$ is the count, not the sum.** A common slip is dividing the sum of reciprocals by the sum of values. Fix: the numerator is always the number of observations.
- **Applying it to negative numbers.** The formula assumes positive values, and negative inputs can produce results outside the range of the data. Fix: use it only on strictly positive data.
- **Reporting more decimal places than the data support.** Speeds measured to the nearest whole number do not justify four decimals. Fix: round the final answer to match the input precision.

## Limitations

The harmonic mean only makes sense for positive, nonzero values. It is undefined when any value is zero and misleading when values are negative. It is also sensitive to small values: a single very low rate pulls the harmonic mean down sharply because its reciprocal is large. That sensitivity is a feature when small values should carry more weight, but it becomes a problem if a low value is an outlier or a data entry error.

It is not a general-purpose average. For most symmetric data without a rate structure, the arithmetic mean is the right choice. The harmonic mean also cannot be interpreted as a typical value in the way the median can, since it is a derived quantity tied to a specific weighting scheme. If your data are ratios without a fixed numerator quantity, think carefully before using it.

## Frequently Asked Questions

### What is the harmonic mean in simple terms?

It is an average built from reciprocals. You flip each value, average the flipped values, then flip the result back. It gives more weight to small values, which is why it fits rates like speed or fuel efficiency.

### When should I use the harmonic mean instead of the arithmetic mean?

Use it when you are averaging rates or ratios and the numerator quantity is constant across observations. Averaging speeds (km per hour) over equal distances (km) is the classic case. If the denominator is constant instead, such as equal driving times, the arithmetic mean is correct.

### Can the harmonic mean be greater than the arithmetic mean?

No, for positive values the harmonic mean is always less than or equal to the arithmetic mean. They are equal only when all values are identical. The gap widens as the values become more spread out.

### What happens if one of my values is zero?

The harmonic mean is undefined because you cannot divide by zero. You need to remove the zero, treat it as a separate case, or use a different average depending on what the zero represents.

### Is the harmonic mean the same as the harmonic average?

Yes, harmonic mean and harmonic average are two names for the same statistic. You may also see the plural "harmonic means" when writers refer to several such averages across different datasets.

## References

This article draws on the standard references listed under Further Reading.

## Further Reading

- [Harmonic Mean](https://archive.lib.msu.edu/crcmath/math/math/h/h092.htm)
- [NIST/SEMATECH e-Handbook of Statistical Methods](https://www.itl.nist.gov/div898/handbook/index.htm)
- [OpenStax. Introductory Statistics 2e](https://openstax.org/details/books/introductory-statistics-2e)
- [Krzywinski M, Altman N (2013). Importance of being uncertain. Nature Methods](https://doi.org/10.1038/nmeth.2613)
- [Krzywinski M, Altman N (2013). Significance, P values and t-tests. Nature Methods](https://doi.org/10.1038/nmeth.2698)
- [Wasserstein RL, Lazar NA (2016). The ASA Statement on p -Values: Context, Process, and Purpose. The American Statistician](https://doi.org/10.1080/00031305.2016.1154108)

## Related Articles

- [Standard Error of the Mean: Formula and Example](/blog/data-analysis/standard-error-of-the-mean-formula)
- [Weighted Arithmetic Mean: Formula and Examples](/blog/data-analysis/weighted-arithmetic-mean-formula-examples)
- [Mean and Standard Deviation: Definition, Formula and Examples](/blog/data-analysis/mean-and-standard-deviation)
- [Geometric Mean: Definition, Formula and Examples](/blog/data-analysis/geometric-mean-definition-formula)
- [Sample Mean: Definition, Formula and Examples](/blog/data-analysis/sample-mean)
- [Mean Square Displacement: Formula and Examples](/blog/research-skills/mean-square-displacement-formula-and-examples)
- [Poisson Distribution: Formula and Examples](/blog/research-skills/poisson-distribution-formula-and-examples)
- [Median Absolute Deviation: Formula and Worked Example](/blog/research-skills/median-absolute-deviation-formula-and-worked-example)