# How to Calculate Cohen's d (Formula and Example)

Cohen's d expresses the difference between two group means in standard deviation units, so you can judge practical significance alongside statistical significance. To calculate it, subtract one mean from the other and divide by the pooled standard deviation. This article shows how to calculate d by hand, in code, and how to read the result.

## Quick Answer

- Cohen's d is the mean difference divided by the pooled standard deviation: $d = (\bar{x}_1 - \bar{x}_2) / s_p$.
- The pooled SD combines both groups' variances, weighted by their degrees of freedom.
- Use the sample standard deviation with $n - 1$ in the denominator for each group.
- Benchmarks: about 0.2 is small, 0.5 is medium, and 0.8 is large [1].
- The sign of d shows direction. The absolute value shows magnitude.

## Before You Start

You need two independent groups and a continuous outcome measured the same way in both. For each group, collect the sample size, the mean, and the standard deviation. If you only have a t value and degrees of freedom from a between-subjects t test, you can still get d, but do not use a paired t test value for this [2].

Decide the direction of your comparison before you compute anything. If you subtract group B from group A, a positive d means group A scored higher. If you reverse the order, the sign flips. The magnitude stays the same.

You also need to know which standard deviation to use. Cohen's d for two independent groups uses the pooled SD, which assumes both groups share a common population variance. If the group sizes or variances differ a lot, read the Limitations section before you report a single number.

## Step by Step

1. **Find each group mean.** Add the values in each group and divide by that group's count.

2. **Subtract the means.** Keep the order consistent with your hypothesis so the sign is meaningful.

3. **Compute each group's standard deviation.** Use the sample formula with $n - 1$ in the denominator.

4. **Square each SD and weight it by its degrees of freedom.** Multiply group A's variance by $n_1 - 1$ and group B's variance by $n_2 - 1$.

5. **Add the weighted variances and divide by the total degrees of freedom.** The denominator is $n_1 + n_2 - 2$.

6. **Take the square root.** That gives you the pooled standard deviation.

7. **Divide the mean difference by the pooled SD.** The result is Cohen's d.

The formula in one line:

$$d = \frac{\bar{x}_1 - \bar{x}_2}{\sqrt{\frac{(n_1 - 1)s_1^2 + (n_2 - 1)s_2^2}{n_1 + n_2 - 2}}}$$

The numerator is the raw mean difference. The denominator is the pooled SD, written $s_p$. Because both parts are in the same units, d is unitless, which is what lets you compare effects across studies that used different scales [1].

## Worked Example

The dataset is test scores for two classes of 12 students each.

| student_id | class_a_score | class_b_score |
|---|---|---|
| 1 | 78 | 72 |
| 2 | 82 | 75 |
| 3 | 85 | 70 |
| 4 | 88 | 68 |
| 5 | 90 | 74 |
| 6 | 84 | 77 |
| 7 | 79 | 71 |
| 8 | 91 | 73 |
| 9 | 86 | 69 |
| 10 | 83 | 76 |
| 11 | 87 | 78 |
| 12 | 80 | 72 |

**Group A mean:** sum of the 12 scores divided by 12 = 84.4167.

**Group B mean:** sum of the 12 scores divided by 12 = 72.9167.

**Mean difference:** 84.4167 - 72.9167 = 11.5000.

**Group A SD (n-1):** 4.2095.

**Group B SD (n-1):** 3.1754.

**Pooled SD numerator:** (11)(4.2095²) + (11)(3.1754²) = 305.8333.

**Pooled SD denominator:** 12 + 12 - 2 = 22.

**Pooled SD:** $\sqrt{305.8333 / 22}$ = 3.7285.

**Cohen's d:** 11.5000 / 3.7285 = 3.0844.

**Interpretation:** |d| = 3.0844, which is a large effect by the 0.2, 0.5, 0.8 benchmarks [1].

Here is the same calculation in Python:

```python
import numpy as np
from math import sqrt
a = [78, 82, 85, 88, 90, 84, 79, 91, 86, 83, 87, 80]
b = [72, 75, 70, 68, 74, 77, 71, 73, 69, 76, 78, 72]
n1, n2 = len(a), len(b)
m1, m2 = np.mean(a), np.mean(b)
s1, s2 = np.std(a, ddof=1), np.std(b, ddof=1)
sp = sqrt(((n1-1)*s1**2 + (n2-1)*s2**2) / (n1+n2-2))
d = (m1 - m2) / sp
print(round(d, 4))  # 3.0844
```

Output:

```
3.0844
```

A dot plot of the two distributions with the group means marked makes the gap visible. The Class A mean sits at 84.42 and the Class B mean at 72.92, and the two clusters barely overlap.

## Other Ways to Do It

If you have a between-subjects t test result, you can convert it. With the t value and the degrees of freedom, an effect size calculator returns d and the effect-size correlation [2]. This is handy when a paper reports t and df but not the group means and SDs.

If you have the means and standard deviations already, enter them directly into the same kind of calculator and it returns d without any hand arithmetic [2]. That reduces rounding errors when you are converting several studies at once.

For a quick estimate, you can also compute d from the standardized mean difference reported in other formats, such as converting from a correlation or from an odds ratio, but those conversions carry assumptions about the underlying distributions. When you have the raw data, the direct formula above is the most transparent route.

If you are working through related descriptive statistics first, the steps for [finding a point estimate](/blog/data-analysis/how-to-find-a-point-estimate) and for the [midrange of a dataset](/blog/data-analysis/how-to-calculate-midrange) use the same mean-and-spread logic you apply here.

## Troubleshooting

**The pooled SD looks wrong.** Check that you squared the SDs before weighting them. A common slip is multiplying the SD by the degrees of freedom instead of the variance.

**d is negative and you expected positive.** You subtracted the groups in the opposite order from your hypothesis. Swap the order or just report the absolute value with a note on direction.

**The two SDs are very different.** The pooled SD assumes a common variance. If one group's SD is several times the other's, consider a variant such as Glass's delta, which uses only the control group's SD.

**Your d is huge.** Very large d values often come from small samples or from groups that barely overlap. Report the group means and SDs next to d so readers can see the raw gap.

**You used a paired t test.** Do not plug a paired t value into the between-subjects conversion. The paired design needs a different effect size that accounts for the correlation between measures [1].

## Common Mistakes

- **Dividing by the wrong SD.** Use the pooled SD for two independent groups, not one group's SD. The fix is to compute the weighted average of the two variances first.
- **Using the population SD.** The sample SD with $n - 1$ is the right choice for estimating d from sample data. Using $n$ in the denominator shrinks the SD and inflates d.
- **Forgetting to square.** The pooling step works with variances. Square each SD, weight it, add, divide, then take the square root.
- **Reporting d without direction.** A bare number loses the sign. State which group was higher so the reader knows the direction.
- **Treating benchmarks as cutoffs.** The 0.2, 0.5, 0.8 labels are rough conventions, not thresholds. Interpret d in the context of your field [1].
- **Mixing up d and the correlation effect size.** They are different scales. If you need the effect-size correlation, compute it separately [2].

## Limitations

Cohen's d summarizes a difference with a single number, and that number hides the shape of the two distributions. Two datasets can share the same d while looking completely different, for example one with a clean separation and another with heavy overlap plus a few extreme values. Always look at the distributions before you trust the summary.

The pooled SD also assumes both groups come from populations with the same variance. When group sizes are unequal and variances differ, d can be biased, and the direction of the bias depends on which group is larger. For small samples, d is a noisy estimate and can swing widely from study to study. Use it as one piece of evidence, not as a verdict on whether an effect matters in practice.

## Frequently Asked Questions

### What is a good Cohen's d value?

There is no universal cutoff. The common convention labels 0.2 as small, 0.5 as medium, and 0.8 as large [1]. What counts as meaningful depends on your field, the cost of the intervention, and the consequences of the decision you are making.

### Can Cohen's d be greater than 1?

Yes. A d above 1 means the mean difference exceeds one pooled standard deviation. Values of 2 or 3 happen when the two groups barely overlap, which is common in controlled lab studies or when comparing very distinct populations.

### How do I calculate d from a t test?

Use the t value and the degrees of freedom from a between-subjects t test. An effect size calculator converts those two inputs into d and the effect-size correlation [2]. Do not use a paired t test value for this conversion [2].

### What is the difference between Cohen's d and Hedges' g?

Both divide the mean difference by a pooled SD. Hedges' g applies a small-sample correction that reduces bias when sample sizes are small. For large samples the two values are nearly identical.

### Does Cohen's d depend on sample size?

The formula itself does not include sample size directly, but the estimate gets more stable as n grows. With small samples, d bounces around a lot, so report confidence intervals or the raw group statistics alongside it.

## References

1. [Lakens D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: a practical primer for t-tests and ANOVAs. Frontiers in psychology](https://pmc.ncbi.nlm.nih.gov/articles/PMC3840331/)
2. [Effect Size Calculators](https://lbecker.uccs.edu/)

## Further Reading

- [NIST/SEMATECH e-Handbook of Statistical Methods](https://www.itl.nist.gov/div898/handbook/index.htm)
- [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)
- [Krzywinski M, Altman N (2013). Significance, P values and t-tests. Nature Methods](https://doi.org/10.1038/nmeth.2698)
- [OpenStax. Introductory Statistics 2e](https://openstax.org/details/books/introductory-statistics-2e)

## Related Articles

- [How to Calculate Midrange: Formula and Examples](/blog/data-analysis/how-to-calculate-midrange)
- [How to Find a Point Estimate: Formula and Examples](/blog/data-analysis/how-to-find-a-point-estimate)
- [Fisher r to z Transformation: Formula and Examples](/blog/data-analysis/fisher-r-to-z-transformation)
- [Null and Alternative Hypotheses: Definition and Examples](/blog/data-analysis/null-and-alternative-hypotheses)
- [What Is a Confidence Interval? Formula and Examples](/blog/data-analysis/confidence-interval-formula-examples)