How to Calculate NDVI in QGIS: 10 Easy Steps

How to Calculate NDVI in QGIS: A Step-by-Step Guide for Students

If you are learning how to calculate NDVI in QGIS, you are working with one of the most widely used vegetation indices in remote sensing. The Normalized Difference Vegetation Index (NDVI) uses the relationship between Near Infrared (NIR) and Red wavelengths to estimate the presence and relative vigor of green vegetation. It is useful for vegetation health analysis, agricultural monitoring, land-cover studies, and environmental GIS projects.

The basic NDVI equation is:

NDVI=NIR−RedNIR+RedNDVI = \frac{NIR – Red}{NIR + Red}

The result normally ranges from -1 to +1. Correctly identifying the NIR and Red bands is critical because using the wrong bands will produce an incorrect vegetation map.


1. What Does NDVI Measure?

Healthy green vegetation strongly absorbs red light for photosynthesis while reflecting relatively large amounts of Near Infrared (NIR) radiation.

NDVI takes advantage of this difference:

  • Healthy vegetation → high NIR reflection + low Red reflection → higher NDVI
  • Bare soil or sparse vegetation → smaller difference → lower NDVI
  • Water → very low or negative NDVI

This makes NDVI useful for quickly examining vegetation patterns across a satellite image.

Why do the bands matter?

NDVI specifically requires:

  1. A Near Infrared (NIR) band
  2. A Red band

Different satellite missions assign different band numbers to these wavelengths. Therefore, you cannot simply use “Band 4” and “Band 5” without checking which satellite produced the imagery.


2. Which Bands Should You Use?

Before opening the Raster Calculator, identify the correct bands for your satellite imagery.

Satellite Red Band NIR Band NDVI Formula
Landsat 8 B4 B5 (B5 - B4) / (B5 + B4)
Landsat 9 B4 B5 (B5 - B4) / (B5 + B4)
Sentinel-2 B4 B8 (B8 - B4) / (B8 + B4)

Landsat 8/9

For Landsat 8 and Landsat 9:

  • B4 = Red
  • B5 = Near Infrared

Therefore:

NDVI=B5−B4B5+B4NDVI = \frac{B5-B4}{B5+B4}

Sentinel-2

For Sentinel-2:

  • B4 = Red
  • B8 = Near Infrared

Therefore:

NDVI=B8−B4B8+B4NDVI = \frac{B8-B4}{B8+B4}

Important: Sentinel-2 also contains B8A, another NIR-related band. For a basic Sentinel-2 NDVI workflow, use B8 and B4 consistently.


3. Prepare Your Satellite Imagery

You need the Red and NIR raster layers before calculating NDVI.

For example, if you are working with Landsat 8, your project might contain:

B4.tif
B5.tif

For Sentinel-2:

B4.tif
B8.tif

You can load them into QGIS using:

Layer → Add Layer → Add Raster Layer

Select the required bands and click Add.

Image

Image

Image

Image

Check the layers

Before calculating NDVI, make sure:

  • Both bands cover the same study area.
  • They have compatible pixel sizes.
  • They use the appropriate coordinate reference system.
  • They are from the same image acquisition date.
  • You are using surface-reflectance or otherwise appropriately processed imagery for your analysis.

Using bands from different dates can produce misleading NDVI patterns because vegetation and atmospheric conditions may have changed.


4. How to Calculate NDVI in QGIS Using the Raster Calculator

The QGIS Raster Calculator performs mathematical operations on raster pixels.

Open it from:

Raster → Raster Calculator

Depending on your QGIS version, you may also find it through the Processing Toolbox by searching for Raster Calculator.

IHow to calculate NDVI in QGIS workflow

Image

Image

Image

Image

Step 1: Select the NIR band

Suppose your Landsat layers are named:

B5
B4

B5 is your NIR band.

Step 2: Select the Red band

B4 is your Red band.

Step 3: Enter the NDVI formula

The fundamental syntax is:

(NIR - Red) / (NIR + Red)

For Landsat 8/9, this becomes:

("B5@1" - "B4@1") / ("B5@1" + "B4@1")

For Sentinel-2:

("B8@1" - "B4@1") / ("B8@1" + "B4@1")

The exact layer names displayed in your Raster Calculator may differ. Use the names shown in your QGIS raster-band list rather than blindly copying the examples.


5. Set the Output Raster

After entering your formula, configure the output.

Choose an output file such as:

NDVI.tif

For the output extent and resolution, it is generally appropriate to match the input raster you are using.

For example:

Output extent: B5
Output resolution: B5

For Sentinel-2 B8/B4, remember that the bands have different native spatial resolutions depending on the products and bands involved. Your workflow should ensure that the input rasters are aligned/resampled appropriately before combining them.

Then click OK or Run, depending on your QGIS version.

QGIS will create a new raster in which each pixel contains an NDVI value.


6. Apply a Color Ramp From -1 to +1

Your newly created NDVI raster may initially appear as a grayscale image. A color classification makes the vegetation patterns much easier to interpret.

Right-click your NDVI layer and select:

Properties → Symbology

Change the rendering method to:

Singleband pseudocolor

Then set the classification range approximately from:

Minimum: -1
Maximum: +1

A common visualization is to use a ramp that progresses from low NDVI values toward increasingly strong vegetation values.

For example:

NDVI range Typical interpretation
-1 to 0 Water, clouds/shadows, or other non-vegetated surfaces
0 to 0.2 Bare soil, rock, built surfaces, or very sparse vegetation
0.2 to 0.8 Increasingly dense/healthy green vegetation

These ranges are guidelines, not universal physical thresholds. Soil background, atmospheric effects, crop type, season, shadows, and sensor characteristics can all affect NDVI.

Image

Image

Image

Image

Image

Image


7. How to Interpret Your NDVI Map

Once the pseudocolor classification is applied, you can begin relating pixel values to actual ground cover.

-1 to 0: Water and non-vegetated surfaces

Negative NDVI values are commonly associated with:

  • Lakes and rivers
  • Wet surfaces
  • Some cloud/shadow pixels
  • Other surfaces where Red reflectance exceeds NIR reflectance

Water commonly produces strongly negative values.

0 to 0.2: Bare or sparsely vegetated surfaces

Low positive values can indicate:

  • Bare soil
  • Sand
  • Rock
  • Urban surfaces
  • Dry or sparse vegetation

0.2 to 0.8: Vegetation

Higher positive values generally indicate greater amounts of green vegetation.

Examples include:

  • Grasslands
  • Cropland
  • Shrubland
  • Forest
  • Dense agricultural vegetation

Very high NDVI does not automatically mean that vegetation is “healthy” in every biological sense. NDVI is primarily a spectral indicator of vegetation greenness and density.


8. Troubleshooting Common NDVI Problems

Problem 1: Your NDVI values look like integers

A common problem occurs when the calculation produces an integer raster instead of a floating-point raster.

NDVI requires decimal values such as:

-0.35
0.12
0.47
0.76

If your output is restricted to integers, much of the useful NDVI information can be lost.

Solution

Check that your input/output raster data type supports floating-point values.

In the Raster Calculator/output settings, choose an appropriate floating-point data type where available, such as:

Float32

This allows decimal NDVI values to be preserved.


Problem 2: Strange values caused by division by zero

The NDVI equation contains:

NIR+RedNIR + Red

in the denominator.

If:

NIR + Red = 0

the calculation attempts to divide by zero.

This can create:

  • NoData pixels
  • Invalid values
  • Artifacts in the resulting raster

Solution

You can protect the calculation using a conditional expression.

Conceptually:

IF(NIR + Red = 0, NULL, (NIR - Red) / (NIR + Red))

For example, a QGIS expression can be structured as:

if(
    ("B5@1" + "B4@1") = 0,
    NULL,
    ("B5@1" - "B4@1") / ("B5@1" + "B4@1")
)

Adapt the band names to your actual raster layers.

This tells QGIS:

If the denominator is zero, return NoData; otherwise calculate NDVI normally.


9. Other Reasons Your NDVI Map May Look Wrong

If your map contains unexpected patterns, check these before assuming the formula is incorrect.

Check your band selection

For Landsat 8/9:

NIR = B5
Red = B4

For Sentinel-2:

NIR = B8
Red = B4

Check that the bands come from the same scene

Don’t combine:

B4 from June
B5 from August

unless you specifically intend to perform a multi-temporal analysis.

Check spatial alignment

The two rasters should have compatible:

  • Extent
  • Pixel size
  • Grid alignment
  • Coordinate reference system

Check preprocessing

Clouds, cloud shadows, atmospheric effects, and other artifacts can appear in an NDVI map and may be mistaken for vegetation changes.

For serious vegetation health analysis, consider using appropriately processed surface-reflectance imagery and masking clouds and shadows before calculating NDVI.


10. Complete NDVI Workflow at a Glance

You can remember the entire QGIS workflow as:

Satellite imagery
       ↓
Identify Red + NIR bands
       ↓
Load rasters into QGIS
       ↓
Check alignment and preprocessing
       ↓
Open Raster Calculator
       ↓
(NIR - Red) / (NIR + Red)
       ↓
Save as Float32 NDVI raster
       ↓
Apply Singleband Pseudocolor
       ↓
Classify approximately -1 to +1
       ↓
Interpret vegetation patterns
       ↓
Perform environmental/agricultural analysis

Quick Reference

Task Landsat 8/9 Sentinel-2
Red B4 B4
NIR B5 B8
Formula (B5-B4)/(B5+B4) (B8-B4)/(B8+B4)
QGIS tool Raster Calculator Raster Calculator
Expected range -1 to +1 -1 to +1
Visualization Singleband Pseudocolor Singleband Pseudocolor

Final Takeaway

Calculating NDVI in QGIS is essentially a three-part process: identify the correct Red and NIR bands, calculate the normalized difference, and visualize the resulting -1 to +1 raster. For Landsat 8/9, use B5 and B4; for Sentinel-2, use B8 and B4.

Once you have the NDVI raster, you can take the analysis further by calculating mean NDVI by agricultural field, comparing vegetation between dates, detecting crop stress, or combining NDVI with land-use and environmental datasets.

Available next action: Create a downloadable DOCX file here in this chat containing the editable prose above