Harmonic mean calculator
No data yet. Enter values in the Harmonic Mean or Weighted tab and the working will appear here.
Harmonic mean formula: quick reference
Every value must be positive and non-zero.
What is the harmonic mean?
The harmonic mean is the reciprocal of the arithmetic mean of the reciprocals. Flip every number, average the flipped values, then flip the answer back. For n positive values that gives H = n / (1/x1 + 1/x2 + … + 1/xn).
It is one of the three Pythagorean means, next to the arithmetic and geometric means, and older texts call it the subcontrary mean. Of the three it is always the smallest, and it stays close to the smallest value in your data. That is exactly why people use it for rates: one slow leg of a trip or one weak recall score drags the answer down, which matches what happens in real life.
This page is the working tool. The harmonic mean guide covers the theory, and the measures of central tendency overview shows where it sits among the other averages. Other tools live in the statistics calculators hub.
Harmonic mean formula
n values
H = n / Σ(1/xi)Two numbers
H = 2ab / (a + b)Three numbers
H = 3abc / (ab + bc + ca)The shortcuts come from adding fractions. For two numbers, 1/a + 1/b = (a + b)/(ab), so H = 2ab/(a + b). For three, 1/a + 1/b + 1/c = (bc + ac + ab)/(abc), which gives the second form above.
Every value has to be positive. A zero has no reciprocal, and negative values stop the idea of an average from making sense, so the calculator warns you and refuses to print a number instead.
Step-by-step examples
Example 1: average speed on a round trip
You drive to a town at 40 km/h and come back the same way at 60 km/h. What was your average speed?
Example 2: four numbers
Find the harmonic mean of 3, 4, 6 and 12.
When to use the harmonic mean
Use the harmonic mean when you are averaging rates or ratios and the same total quantity sits behind each one, for example equal distances traveled at different speeds or equal capital placed at different P/E ratios.
| Situation | Best mean | Reason |
|---|---|---|
| Speed over equal distances | Harmonic | Time is distance divided by speed |
| P/E ratios, equal money per stock | Harmonic | Earnings sit in the denominator |
| F1 score from precision and recall | Harmonic | Punishes a big gap between the two |
| Growth rates over several years | Geometric | Rates compound by multiplication |
| Test scores or heights | Arithmetic | Independent values with equal weight |
Real-world applications
Average speed
Drive 60 km at 40 km/h, then 60 km at 60 km/h. The first leg takes 1.5 hours and the second takes 1 hour, so 120 km in 2.5 hours is 48 km/h. If you drove for equal time at each speed instead, the arithmetic mean of 50 km/h would be right. The test is simple: which quantity is held equal? Equal distance calls for the harmonic mean.
Finance: averaging P/E ratios
Put equal amounts into three stocks with P/E ratios of 10, 15 and 30. H = 3 / (1/10 + 1/15 + 1/30) = 3 / (6/30) = 15. The arithmetic mean says 18.3, which the 30 pulls upward. The harmonic result is the honest one: each dollar buys earnings of 1/10, 1/15 and 1/30, the average of those is 1/15, and that is a P/E of 15. This assumes equal capital in each position. For unequal positions use the weighted version below.
Machine learning: the F1 score
The F1 score is the harmonic mean of precision (P) and recall (R): F1 = 2PR / (P + R). Take a model with P = 100% and R = 0%. The arithmetic mean reports a comfortable 50%, while F1 = 0, which is the truth: the model finds nothing. With P = 0.9 and R = 0.6, F1 = 2(0.54)/1.5 = 0.72, a bit under the arithmetic 0.75. You can get both inputs from the confusion matrix calculator, and the mean calculator shows the arithmetic comparison.
Physics: parallel resistors
For n resistors in parallel, 1/Req = 1/R1 + … + 1/Rn. That makes Req = H/n, the harmonic mean divided by n. Two 10 Ω resistors give H = 10 and Req = 5 Ω. A 20 Ω and a 30 Ω resistor give H = 24 and Req = 12 Ω. A related geometry fact: the harmonic mean of a triangle's three altitudes equals three times its inradius.
The AM-GM-HM inequality
For any set of positive numbers, the arithmetic mean is at least the geometric mean, which is at least the harmonic mean: A ≥ G ≥ H. The three match only when every value is identical. Take 3, 4 and 6:
| Mean | Calculation | Value |
|---|---|---|
| Arithmetic (A) | (3 + 4 + 6) / 3 | 4.333 |
| Geometric (G) | (3 × 4 × 6)1/3 = 721/3 | 4.160 |
| Harmonic (H) | 3 / (1/3 + 1/4 + 1/6) = 3 / (9/12) | 4.000 |
For exactly two numbers there is a tidy link: G² = A × H. With 40 and 60, A = 50, H = 48 and G² = 2400 = 50 × 48. Check the others with the geometric mean calculator and the arithmetic mean calculator, or read the geometric mean guide.
Weighted harmonic mean
When values carry different importance, use Hw = Σwi / Σ(wi / xi). The ordinary harmonic mean is the special case where every weight is equal.
Back to the portfolio: P/E ratios of 10, 15 and 30, but now 60%, 25% and 15% of the money. The sum of w/x is 0.06 + 0.0167 + 0.005 = 0.0817, so Hw = 1 / 0.0817 ≈ 12.24. The weighted arithmetic mean would say 14.25. Most of the money sits in the cheap stock, and the harmonic version reflects that. Try it in the Weighted tab. For plain weighted averages, see the weighted average calculator and the weighted mean guide.
Related calculators and guides
This calculator belongs to the statistics calculators collection, and the concept sits under descriptive statistics.
Further reading
- Wolfram MathWorld, Harmonic Mean
- Wikipedia, Harmonic mean
- scikit-learn documentation, f1_score
Frequently Asked Questions
The harmonic mean is a type of average calculated using the reciprocals of a set of positive numbers. It is commonly used to average rates, speeds, and ratios.
Divide the number of values by the sum of their reciprocals. The formula is H = n / (1/x₁ + 1/x₂ + ... + 1/xₙ).
The harmonic mean formula is H = n / Σ(1/x). Here, n represents the total number of values, and x represents each individual value.
The harmonic mean of 40 and 60 is 48. It is calculated as (2 × 40 × 60) / (40 + 60) = 48.
Use the harmonic mean when calculating averages involving rates or ratios, such as average speed over equal distances or financial ratios.
No. The standard harmonic mean requires positive numbers. Zero cannot be used because its reciprocal is undefined.
The arithmetic mean is calculated by adding values and dividing by their count. The harmonic mean uses reciprocals and is more suitable for averaging rates and ratios.
The harmonic mean is used in statistics to calculate average rates, ratios, and measures such as the F1 score in machine learning.