{
  "id": "shannon-diversity-index",
  "version": "a9a5ea99e722",
  "status": "published",
  "name": "Shannon Diversity Index Calculator",
  "question": "What is the Shannon diversity index?",
  "summary": "Computes the Shannon diversity index H = −Σ p ln p from the number of individuals of each species, with the evenness (equitability) H ÷ ln S and the species count, in natural log, base 2 or base 10.",
  "category": "biology",
  "url": "https://www.acalculator.org/biology/shannon-diversity-index-calculator",
  "markdown": "https://www.acalculator.org/biology/shannon-diversity-index-calculator.md",
  "kind": "function",
  "method": "p = n ÷ N for each species; H = −Σ p ln p (divided by ln 2 or ln 10 for base 2 or 10); evenness = H ÷ ln S, the same in any base.",
  "assumptions": [
    "Each count is the number of individuals of one species (or its cover or proportion); N is their sum and S the number of species with a count above 0.",
    "Species with a count of 0 are left out: p ln p is taken as 0 for them.",
    "Natural logarithms are the usual choice in ecology; base 2 gives H in bits."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "n": {
        "title": "Individuals of each species",
        "description": "How many individuals of each species were counted (or each one’s cover or proportion), separated by commas, spaces or new lines.",
        "type": "array",
        "items": {
          "type": "number"
        }
      },
      "b": {
        "title": "Logarithm",
        "description": "The base of the logarithm: natural log (nats, the usual choice), base 2 (bits) or base 10.",
        "type": "string",
        "enum": [
          "e",
          "2",
          "10"
        ]
      }
    }
  },
  "outputs": {
    "h": {
      "label": "Shannon diversity index (H)",
      "description": "−Σ p log p over the species, in the chosen base.",
      "format": "number"
    },
    "evenness": {
      "label": "Evenness (H ÷ Hmax)",
      "description": "H divided by its largest possible value, log S; from 0 to 1.",
      "format": "number"
    },
    "hmax": {
      "label": "Largest possible H (log S)",
      "description": "H when all S species are equally common.",
      "format": "number"
    },
    "richness": {
      "label": "Species (S)",
      "description": "The number of species with a count above 0.",
      "format": "integer"
    },
    "total": {
      "label": "Total (N)",
      "description": "The sum of all the counts.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "n": "25, 15, 40, 20",
      "b": "e"
    },
    "outputs": {
      "h": 1.3195454632493369,
      "evenness": 0.9518508480286741,
      "hmax": 1.3862943611198906,
      "richness": 4,
      "total": 100
    },
    "text": "The Shannon diversity index is H = 1.31955 for 4 species."
  },
  "examples": [
    {
      "given": {
        "n": [
          25,
          15,
          40,
          20
        ],
        "b": "e"
      },
      "expect": {
        "h": 1.3195454632493369,
        "evenness": 0.9518508480286741,
        "hmax": 1.3862943611198906,
        "richness": 4,
        "total": 100
      },
      "source": "NIST, Dataplot Reference Manual, SHANNON DIVERSITY INDEX (H = −Σ p_i log p_i; maximum log k; equitability E_H = H ÷ log k; proportions 0.25, 0.15, 0.40, 0.20 give 1.319545 and 0.9518508; Shannon 1948), https://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/shannon.htm (retrieved 2026-10-18); hand calculation in content.mdx"
    },
    {
      "given": {
        "n": [
          5,
          5,
          5,
          5
        ],
        "b": "2"
      },
      "expect": {
        "h": 2,
        "evenness": 1,
        "hmax": 2
      },
      "source": "Shannon, C. E. (1948), A Mathematical Theory of Communication, Bell System Technical Journal 27, 379–423 and 623–656 (H = −K Σ p_i log p_i; the base sets the unit: 2 gives bits), https://doi.org/10.1002/j.1538-7305.1948.tb01338.x; NIST, Dataplot Reference Manual, SHANNON DIVERSITY INDEX (H = −Σ p_i log p_i; maximum log k; equitability E_H = H ÷ log k; proportions 0.25, 0.15, 0.40, 0.20 give 1.319545 and 0.9518508; Shannon 1948), https://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/shannon.htm (retrieved 2026-10-18); hand calculation in content.mdx: −4 × 0.25 × log₂ 0.25 = 2 bits"
    },
    {
      "given": {
        "n": [
          90,
          5,
          5
        ],
        "b": "e"
      },
      "expect": {
        "h": 0.39439769144744274,
        "evenness": 0.3589962496465303,
        "richness": 3
      },
      "source": "NIST, Dataplot Reference Manual, SHANNON DIVERSITY INDEX (H = −Σ p_i log p_i; maximum log k; equitability E_H = H ÷ log k; proportions 0.25, 0.15, 0.40, 0.20 give 1.319545 and 0.9518508; Shannon 1948), https://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/shannon.htm (retrieved 2026-10-18); hand calculation in content.mdx: −(0.9 ln 0.9 + 2 × 0.05 ln 0.05)"
    },
    {
      "given": {
        "n": [
          10,
          0,
          10
        ],
        "b": "10"
      },
      "expect": {
        "h": 0.30102999566398114,
        "evenness": 1,
        "richness": 2
      },
      "source": "NIST, Dataplot Reference Manual, SHANNON DIVERSITY INDEX (H = −Σ p_i log p_i; maximum log k; equitability E_H = H ÷ log k; proportions 0.25, 0.15, 0.40, 0.20 give 1.319545 and 0.9518508; Shannon 1948), https://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/shannon.htm (retrieved 2026-10-18); hand calculation in content.mdx: log₁₀ 2 = 0.30103"
    }
  ],
  "sources": [
    "NIST, Dataplot Reference Manual, SHANNON DIVERSITY INDEX: H = −Σ p_i log(p_i), or [n log n − Σ f_i log f_i] ÷ n for counts; the maximum is log k; the Shannon equitability index E_H = H ÷ log k; proportions 0.25, 0.15, 0.40, 0.20 give 1.319545 and 0.9518508. https://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/shannon.htm (retrieved 2026-10-18)",
    "Shannon, C. E. (1948), A Mathematical Theory of Communication, Bell System Technical Journal 27, 379–423 and 623–656: the entropy H = −K Σ p_i log p_i, in bits for base 2. https://doi.org/10.1002/j.1538-7305.1948.tb01338.x"
  ],
  "related": [
    "simpsons-diversity-index",
    "hardy-weinberg",
    "log"
  ],
  "changelog": []
}
