Skip to main content
v2026.11,858 entries · CC-BY 4.0

Bray-Curtis Dissimilarity: Formula, Worked Example and Code

Bray-Curtis dissimilarity compares two samples on a 0-1 scale. Formula, worked example, interpretation, and R, Python and Excel code.

Written and maintained by CASRAI Editorial Board

Last updated

Bray-Curtis dissimilarity is a number between 0 and 1 that says how different two samples are, based on the counts of each species (or any other count variable) in them. A value of 0 means the two samples contain exactly the same quantities of everything; a value of 1 means they share nothing. This guide gives the formula in both of its standard forms, a worked example with every step of the arithmetic, and code for R, Python and Excel.

What is Bray-Curtis dissimilarity?

Bray-Curtis dissimilarity (often searched as “bray curtis” or “bray-curtis dissimilarity”) compares two sites, samples or objects by the total absolute difference between their counts, scaled by the total of their counts. It was introduced by J. Roger Bray and John T. Curtis in a 1957 paper in Ecological Monographs (volume 27, pages 325-349) and is now a default tool for community ecology, microbiome analysis and beta diversity. The vegan package for R documents it as the default method of vegdist().

It is a dissimilarity, not a similarity: larger means more different. To get a similarity, subtract it from 1.

Bray-Curtis dissimilarity formula

For two samples j and k measured on the same n species, the quantitative form given in the vegan documentation is:

djk = Σi |xij − xik| ÷ Σi (xij + xik)

  • xij: the abundance (count) of species i in sample j; xik is the same for sample k.
  • |xij − xik|: the absolute difference for that species, so over- and under-representation do not cancel.
  • Σi: the sum over all species i.
  • The denominator is the total abundance of both samples combined.

SciPy states the same formula as d(u, v) = Σ|ui − vi| ÷ Σ|ui + vi|, and notes the result lies in [0, 1] when all coordinates are positive. SciPy also accepts optional weights.

The equivalent “shared abundance” form

For non-negative counts the same value can be written as 1 − 2C ÷ (Sj + Sk), where Sj and Sk are the total counts in each sample and C is the sum, over species, of the smaller of the two counts (the abundance the samples have in common). This follows algebraically from the formula above, because |a − b| = a + b − 2·min(a, b). The worked example below computes both forms.

The presence/absence (binary) form

vegan also documents a binary version, (A + B − 2J) ÷ (A + B), where A and B are the numbers of species in each sample and J is the number the samples share. It equals the Sørensen dissimilarity. In vegan you request it with binary = TRUE.

Worked example with real numbers

Two sites, five species. The counts are invented for illustration.

Species Site A Site B |A − B| A + B min(A, B)
1 8 4 4 12 4
2 3 3 0 6 3
3 0 6 6 6 0
4 5 0 5 5 0
5 2 1 1 3 1
Total 18 14 16 32 8
  1. Absolute-difference form: 16 ÷ 32 = 0.50.
  2. Shared-abundance form: C = 8, SA = 18, SB = 14, so 1 − (2 × 8) ÷ (18 + 14) = 1 − 16 ÷ 32 = 0.50.

Both forms agree. On presence/absence alone, site A has 4 species, site B has 4, and they share 3 (species 1, 2 and 5), so the binary form is (4 + 4 − 2×3) ÷ (4 + 4) = 2 ÷ 8 = 0.25. The two values differ because abundance information changes the answer: the sites share most species but in quite different quantities.

How to interpret the value

Value What it means
0 The two samples have identical abundances for every species.
Between 0 and 1 Partial overlap. The example above gives 0.50: half of the combined abundance is unmatched between the sites.
1 No species in common. In SciPy’s documentation, braycurtis([1,0,0],[0,1,0]) returns 1.0.

A useful reading of the middle of the scale is the shared-abundance form: 1 − d is the share of the combined abundance that the two samples have in common. A value of 0.33 for [1,1,0] versus [0,1,0] (SciPy’s own example: numerator 1, denominator 3) means one unit of the three combined units is unmatched. No universal cut-off separates “similar” from “different”; judge values against the other pairs in your data set.

Assumptions and common mistakes

Is Bray-Curtis a true distance?

No. The vegan documentation calls it a semimetric: it does not guarantee the triangle inequality. A small check: for x = (1, 0), y = (1, 1) and z = (0, 1), d(x, y) = 1 ÷ 3, d(y, z) = 1 ÷ 3, but d(x, z) = 1, which is larger than 1 ÷ 3 + 1 ÷ 3. The same documentation says Jaccard “is metric, and probably should be preferred instead of the default Bray-Curtis”. Jaccard is computed there as 2B ÷ (1 + B), where B is the Bray-Curtis value, so the two rank pairs of samples in the same order. For the binary example above, B = 0.25 gives 2 × 0.25 ÷ 1.25 = 0.40, which matches 1 − 3 ÷ 5 for the Jaccard form.

Common mistakes

  • Negative values. vegan warns that most of its dissimilarity indices are designed for community data and give misleading values if there are negative entries. Do not feed in log-ratios or centred data.
  • Empty samples. A sample whose counts are all zero makes the denominator zero when compared with another empty sample, so the result is undefined (NaN or NA). Remove empty rows first.
  • Different sampling effort. The formula compares raw totals. If one sample has twice the total count of the other for reasons of effort, not ecology, the difference will show up as dissimilarity. Decide whether to rarefy or transform before computing.
  • Reading it as a similarity. 0 means identical, 1 means nothing shared.

How to report it

State the index, the data transformation (if any) and the values. For example:

Community composition differed between the two sites (Bray-Curtis dissimilarity = .50, computed on untransformed counts of five species; Bray and Curtis, 1957).

When you report many pairs, give a table of the dissimilarity matrix or a summary such as the median and range, and name the software and function (for example, vegdist() in the vegan package for R, or scipy.spatial.distance.braycurtis in SciPy).

Bray-Curtis in R, Python and Excel

R (base R and vegan)

Base R, using the formula directly:

a <- c(8, 3, 0, 5, 2)
b <- c(4, 3, 6, 0, 1)
sum(abs(a - b)) / sum(a + b)   # 0.5

With vegan, where each row is a site (Bray-Curtis is the default method, and binary = FALSE keeps abundances):

library(vegan)
x <- rbind(a, b)
vegdist(x, method = "bray")

Add binary = TRUE for the presence/absence form (0.25 for this example). The vegan documentation’s own example is data(varespec); vare.dist <- vegdist(varespec).

Python (SciPy)

from scipy.spatial import distance
a = [8, 3, 0, 5, 2]
b = [4, 3, 6, 0, 1]
distance.braycurtis(a, b)   # 0.5

Excel

Excel has no built-in Bray-Curtis function. Because counts are non-negative, the formula can be written as plain arithmetic. With site A in A2:A6 and site B in B2:B6:

=SUMPRODUCT(ABS(A2:A6-B2:B6))/SUM(A2:A6,B2:B6)

This returns 0.5 for the example data. It is an arithmetic equivalent of the formula, valid only for non-negative values.

Related pages on CASRAI

If you are choosing between analyses, see our guide to clustering analysis in R, which is where a dissimilarity matrix is typically used next. For the statistics around it, read about effect size, descriptive versus inferential statistics, and the Shapiro-Wilk test in R for checking normality when you move on to testing group differences. Our linear regression worked examples in Excel, R and Python show the same side-by-side format.

FAQ

What is the Bray-Curtis dissimilarity formula?

Sum the absolute differences in species counts between two samples and divide by the sum of all the counts in both samples: d = Σ|xij − xik| ÷ Σ(xij + xik).

What range does Bray-Curtis take?

0 to 1 for non-negative data, where 0 is identical and 1 is no overlap (SciPy documents the [0, 1] range for positive coordinates).

Is Bray-Curtis the same as Sørensen?

The binary (presence/absence) form of Bray-Curtis equals the Sørensen dissimilarity, per the vegan documentation. The quantitative form uses abundances and gives different values.

Should I use Bray-Curtis or Jaccard?

vegan notes that Jaccard is a metric and probably should be preferred over the default Bray-Curtis, and that Jaccard equals 2B ÷ (1 + B) of the Bray-Curtis value B, so rank-based analyses give similar results.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Bray-Curtis Dissimilarity: Formula, Worked Example and Code

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.