Harmonic Mean Calculator Formula

Understand the math behind the harmonic mean calculator. Each variable explained with a worked example.

Formulas Used

Harmonic Mean

harm_mean = 2 / (1/a + 1/b)

Arithmetic Mean (for comparison)

arith_mean = (a + b) / 2

Variables

VariableDescriptionDefault
aValue 140
bValue 260
recip_sumDerived value= 1/a + 1/bcalculated

How It Works

How to Compute the Harmonic Mean

Formula (for two values)

Harmonic Mean = 2 / (1/a + 1/b)

More generally for n values: HM = n / (1/v1 + 1/v2 + ... + 1/vn)

The harmonic mean gives more weight to smaller values. It is the correct average to use when the quantities are defined in relation to a common unit, such as speed over the same distance at different rates.

Worked Example

A car travels 100 km at 40 km/h and returns at 60 km/h. What is the average speed?

a = 40b = 60
  1. 01Reciprocal sum = 1/40 + 1/60 = 0.025 + 0.01667 = 0.04167
  2. 02Harmonic Mean = 2 / 0.04167 = 48
  3. 03The average speed is 48 km/h (not 50 as the arithmetic mean would suggest)

When to Use This Formula

  • Averaging speeds for a round trip — if you drive 60 km/h one way and 40 km/h back, the harmonic mean (48 km/h) is the correct average speed, not the arithmetic mean (50 km/h).
  • Calculating the average price-to-earnings ratio of a stock portfolio when individual P/E ratios vary widely, because the harmonic mean reduces the distortion from extreme outliers.
  • Computing the effective resistance of resistors in parallel, which uses the reciprocal-sum structure that is mathematically equivalent to a harmonic mean.
  • Averaging rates of any kind — production rates, data transfer speeds, fuel efficiency — whenever equal quantities (not equal times) are spent at each rate.
  • Calculating the F1 score in machine learning, which is the harmonic mean of precision and recall, penalizing models that are strong on one metric but weak on the other.

Common Mistakes to Avoid

  • Using the arithmetic mean instead of the harmonic mean for averaging rates — the arithmetic mean of 60 and 40 is 50, but the true average speed for equal distances is 48. The error grows as the rates diverge.
  • Including zero in the dataset — the harmonic mean requires taking reciprocals (1/xi), so any zero value makes the calculation undefined. Unlike the arithmetic mean, you cannot simply include zeros.
  • Including negative values — the harmonic mean is only defined for positive numbers. Mixing positive and negative values can produce a result that is mathematically valid but practically meaningless.
  • Assuming the harmonic mean is always appropriate for "averages" — it is correct only when averaging rates or ratios where the numerator is fixed. When the denominator is fixed, the arithmetic mean is correct.

Frequently Asked Questions

When should I use the harmonic mean?

Use it when averaging rates or ratios measured over the same base quantity, such as speeds over equal distances or price-to-earnings ratios.

Why is the harmonic mean always the smallest of the three Pythagorean means?

For any set of positive unequal values, Harmonic Mean <= Geometric Mean <= Arithmetic Mean. The harmonic mean is pulled toward the smaller values because it averages reciprocals.

Can the harmonic mean handle zero values?

No. A zero value causes a division by zero in the reciprocal, making the harmonic mean undefined.

Ready to run the numbers?

Open Harmonic Mean Calculator