Gis, Qgis, ArcGis  Experts Just a Click Away

NDVI Calculation Using QGIS Raster Calculator

How to Calculate NDVI in QGIS Raster Calculator

The Normalized Difference Vegetation Index (NDVI) compares red and near-infrared reflectance to highlight differences in vegetation response. It is widely used for vegetation mapping, crop monitoring, ecological studies, and change analysis.

The calculation is simple, but a reliable result depends on more than entering a formula. You must use the correct sensor bands, ensure that the bands line up, understand the pixel values and scaling, mask clouds and invalid pixels, handle NoData and zero denominators, and interpret the output in its environmental and seasonal context.

This guide shows how to calculate NDVI in QGIS using the Raster Calculator and how to validate the result for Landsat and Sentinel-2 data.

What NDVI measures

Healthy photosynthesizing vegetation generally absorbs red light for photosynthesis and reflects much of the near-infrared (NIR) energy. NASA describes NDVI as the difference between NIR and red surface reflectance divided by their sum. 1

The standard formula is:

NDVI = (NIR - Red) / (NIR + Red)

The result is theoretically bounded by -1 and +1 when the input values are non-negative and the denominator is not zero. Higher values often indicate more vigorous or denser green vegetation, while low or negative values can occur over water, bare ground, snow, clouds, shadows, or nonvegetated surfaces.

NDVI is an indicator, not a direct measurement of plant health, biomass, yield, or photosynthetic rate. Its value depends on vegetation type, canopy structure, soil background, atmosphere, illumination, sensor, season, and preprocessing.

What you need before starting

You need:

  • QGIS with the Raster Calculator available
  • A red-band raster
  • A near-infrared-band raster
  • A known sensor and product type
  • Georeferenced imagery
  • Bands with compatible grids, extent, resolution, and pixel alignment
  • A plan for cloud, shadow, snow, and NoData masking
  • Enough storage for the output GeoTIFF

Prefer surface-reflectance products that have already undergone appropriate atmospheric correction when your analysis requires quantitative comparison. Top-of-atmosphere reflectance or digital numbers can still be used in some workflows, but the product type and scaling must be understood and documented.

Select the correct red and NIR bands

Do not rely only on filenames such as B04 or B5. Band numbering differs between sensors.

Landsat 4–7

For Landsat 4–7 TM/ETM+ data:

  • Red = Band 3
  • NIR = Band 4

USGS gives the Landsat 4–7 expression as:

(Band 4 - Band 3) / (Band 4 + Band 3)

Landsat 8–9

For Landsat 8–9 OLI data:

  • Red = Band 4
  • NIR = Band 5

USGS gives the Landsat 8–9 expression as:

(Band 5 - Band 4) / (Band 5 + Band 4)

These assignments are for the standard Landsat multispectral bands and should not be confused with thermal or quality-assessment bands. 2

Sentinel-2

For Sentinel-2 MSI data:

  • Red = B04
  • NIR = B08

Copernicus documentation identifies B04 as the red band at 10 m and B08 as the NIR band at 10 m. B8A is a narrow NIR band at 20 m and is not identical to B08. 3

For a common Sentinel-2 NDVI calculation, use B04 and B08 unless your methodology specifically requires B8A and documents the difference.

Other sensors

MODIS, Planet, WorldView, aerial cameras, and drone sensors have different band names, spectral responses, resolutions, and calibration. Find the sensor’s product documentation and verify which band is red and which is NIR.

Check whether the bands align

Raster Calculator combines pixels by grid position. Before calculating, confirm that the red and NIR rasters have:

  • The same coordinate reference system or a valid on-the-fly relationship
  • The same pixel size
  • The same extent or a deliberately chosen overlap
  • The same row and column alignment
  • Compatible NoData definitions
  • Compatible acquisition time or scene

If the bands do not share a grid, resample one to the other before calculation. QGIS notes that when the Raster Calculator output resolution differs from an input, values are resampled using nearest neighbor. 4

For continuous reflectance, you may prefer bilinear resampling during a deliberate preprocessing step. For categorical masks, nearest neighbor is usually appropriate. Do not allow an unnoticed grid mismatch to determine the resampling method.

Sentinel-2 B04 and B08 are both 10 m in the cited product documentation, which makes them a straightforward pair. If you use B8A, a 20 m band, align it intentionally with the red band.

Understand scaling and reflectance values

The NDVI ratio is not automatically safe for every digital-number product.

Sentinel-2 digital numbers

For Sentinel-2 optical data, Copernicus documentation describes the relationship:

DN = 10000 × reflectance

If red and NIR use the same multiplicative scale and no additive offset is present, the scale factor cancels in the normalized ratio. You can often calculate NDVI from the matching raw optical DN bands, provided they come from the same product and have compatible masking and processing. 3

Still check the product documentation, especially when data has been harmonized, resampled, mosaicked, or delivered through a service with values already converted to reflectance.

Landsat Collection 2 Level-2 surface reflectance

USGS documents the Landsat Collection 2 surface-reflectance conversion as:

Surface reflectance = (DN × 0.0000275) - 0.2

The additive offset matters. Applying only the scale factor and ignoring the offset can change the NDVI ratio. 5

For Landsat Collection 2 Level-2 SR, either:

  1. Convert the red and NIR bands to reflectance first and then calculate NDVI; or
  2. Include the scale and offset directly in the Raster Calculator expression.

For Landsat 8–9, the direct expression can be written as:

(("NIR_DN@1" * 0.0000275 - 0.2) - ("RED_DN@1" * 0.0000275 - 0.2)) /
(("NIR_DN@1" * 0.0000275 - 0.2) + ("RED_DN@1" * 0.0000275 - 0.2))

Replace the layer names with the exact names shown in your QGIS Raster Calculator. Check the product metadata before using this expression; scaling differs between products and processing levels.

Do not mix incompatible products

Do not calculate NDVI from:

  • Red reflectance and NIR raw DN
  • A surface-reflectance red band and a top-of-atmosphere NIR band
  • Different acquisition dates without a time-series design
  • Bands with different atmospheric corrections
  • A resampled mask treated as reflectance

The two input bands must represent comparable measurements.

Prepare the imagery

Atmospheric correction

For comparisons across dates or locations, use a documented surface-reflectance product or an appropriate atmospheric-correction workflow. A visually attractive RGB image is not proof that the pixel values are ready for quantitative vegetation analysis.

Cloud and shadow masking

Clouds, cloud shadows, cirrus, snow, and saturated pixels can create extreme or misleading NDVI values. Use the quality-assurance or scene-classification layer supplied with the product.

For Sentinel-2 L2A, the Scene Classification Layer includes classes such as cloud shadows, vegetation, bare soil, water, clouds, cirrus, and snow or ice. 3

For Landsat, use the product’s quality-assessment bands and documented bit flags. The exact bit interpretation depends on the product collection and processing level.

Crop to an area of interest

If you only need a study area, clip the red, NIR, and mask rasters before calculation. This reduces processing time and output size. Keep the unclipped source data for reproducibility.

Check statistics and NoData

Inspect minimum, maximum, mean, and NoData values for both bands. Unexpected negative values or very large values may be valid for a particular product, but they should be investigated against metadata.

Calculate NDVI in QGIS Raster Calculator

Step 1: Load the bands

  1. Open QGIS.
  2. Select Layer → Add Layer → Add Raster Layer.
  3. Add the red and NIR rasters.
  4. Add the cloud or quality mask if you will use one.
  5. Confirm the layers overlap correctly.
  6. Use Zoom to Layer and inspect the imagery.

Step 2: Open Raster Calculator

Select Raster → Raster Calculator. QGIS lists loaded raster layers and bands in the Raster Bands panel. Double-click a band to insert its exact reference into the expression. QGIS identifies bands in the form:

layer_name@band_number

For example:

"Sentinel_B08@1"
"Sentinel_B04@1"

Using the band reference inserted by QGIS reduces typing errors. 4

Step 3: Enter the formula

Landsat 8–9 example

If your layers are named Landsat_B5 and Landsat_B4:

("Landsat_B5@1" - "Landsat_B4@1") /
("Landsat_B5@1" + "Landsat_B4@1")

Sentinel-2 example

If your layers are named S2_B08 and S2_B04:

("S2_B08@1" - "S2_B04@1") /
("S2_B08@1" + "S2_B04@1")

Generic form

("NIR_LAYER@1" - "RED_LAYER@1") /
("NIR_LAYER@1" + "RED_LAYER@1")

Do not copy the example names literally. Insert the bands from your own project.

Step 4: Handle a zero denominator

Where both red and NIR are zero, the denominator is zero and NDVI is undefined. A guarded expression can return NoData for those cells:

if(
  ("NIR_LAYER@1" + "RED_LAYER@1") = 0,
  NULL,
  ("NIR_LAYER@1" - "RED_LAYER@1") /
  ("NIR_LAYER@1" + "RED_LAYER@1")
)

Test the expression in your QGIS version. If your input already carries NoData in invalid areas, those cells should be handled consistently in the output.

Step 5: Configure the result layer

In the Result Layer section:

  • Choose an output file path.
  • Select GeoTIFF for a broadly compatible analysis output.
  • Set the calculation extent deliberately.
  • Set the output resolution and alignment intentionally.
  • Choose a floating-point output type where available.
  • Enable creation options such as compression when appropriate.
  • Add the result to the project.

QGIS allows a calculation to be written to disk or created as an on-the-fly virtual raster. A virtual raster remains connected to the source rasters, so moving or deleting them can break the result. 4

For a permanent NDVI result, write a GeoTIFF to disk and retain the source-band paths and expression in your processing notes.

Step 6: Run the calculation

Click OK or Run, depending on the QGIS interface. Wait for processing to complete and inspect the new NDVI layer.

Calculate NDVI with the Processing Toolbox

You can also use the Processing Toolbox Raster Calculator algorithm. The same principles apply:

  • Select the exact bands.
  • Use the correct formula.
  • Set extent and resolution.
  • Choose a floating output type.
  • Save the result rather than relying only on a temporary layer.

The Processing Toolbox is useful when you want to add the operation to a model or repeat it for many scenes.

Apply a cloud and invalid-pixel mask

Calculate the index first only when you understand the quality of the input. For analysis, masking is often better than interpreting cloud-contaminated results.

Mask before calculation

Use the quality layer to create cleaned red and NIR inputs, or use a raster mask so invalid pixels become NoData before the ratio is calculated.

Mask after calculation

You can calculate NDVI and then use a conditional expression to preserve valid NDVI only where the mask indicates acceptable pixels. The exact expression depends on the quality layer’s class codes.

A generic pattern is:

if(
  "VALID_MASK@1" = 1,
  "NDVI@1",
  NULL
)

Do not copy VALID_MASK@1 without checking whether 1 actually means valid in your product. Sentinel-2 SCL and Landsat QA layers use product-specific classes or bit flags.

Why masking matters

A cloud can have low or unusual red and NIR reflectance and may produce values that look like vegetation or water. Shadows, snow, and saturated pixels can be equally misleading. A map with a smooth color ramp is not necessarily a valid vegetation map.

Style the NDVI raster

Use Singleband pseudocolor

  1. Right-click the NDVI layer.
  2. Select Properties.
  3. Open Symbology.
  4. Choose Singleband pseudocolor.
  5. Set a meaningful min/max range.
  6. Choose a color ramp.
  7. Apply and inspect the map.

A red-to-yellow-to-green ramp is common, but color choice should match the map’s audience and accessibility requirements. A color ramp is a visual encoding, not a scientific classification by itself.

Do not stretch blindly to outliers

If a few invalid pixels have extreme values, an automatic stretch can make the vegetation pattern difficult to see. First mask invalid pixels and inspect the value distribution. Consider using a documented percentile stretch for display while retaining the original floating-point values for analysis.

Use a fixed range for comparisons

For a time series or comparison between scenes, use a consistent color range and class definition. Stretching each scene independently can make two dates look equally green even when their numerical distributions differ.

Interpreting NDVI values

Typical broad interpretations are useful as a starting point, not as universal thresholds:

  • Values near or below 0: often water, cloud, snow, shadow, or nonvegetated surfaces
  • Low positive values: bare soil, rock, sparse vegetation, or mixed pixels
  • Moderate positive values: grassland, crops, shrubland, or partially vegetated surfaces
  • Higher positive values: dense green vegetation or closed canopy

The exact value depends on sensor, atmosphere, soil background, canopy structure, phenological stage, sun angle, spatial resolution, and preprocessing. NASA describes the general relationship between higher NDVI and healthier or denser vegetation, but the index must be interpreted in context. 1

Do not use a fixed table such as “0.6–0.8 always means forest” for every landscape. A dense crop canopy, wet grassland, forest, and mixed urban vegetation can have overlapping values.

NDVI is not a direct health score

NDVI can respond to vegetation stress, but it does not identify the cause of a change. A lower value may result from:

  • Drought
  • Disease
  • Harvesting
  • Mowing
  • Seasonal dormancy
  • Cloud or shadow contamination
  • Soil exposure
  • Different atmospheric conditions
  • Different sun or view geometry
  • Misregistration between bands
  • Different sensor or processing product

Use field observations, weather data, crop calendars, land-cover information, and other indices where a causal interpretation is required.

Compare NDVI across dates correctly

For temporal analysis:

  1. Use the same sensor or a documented cross-sensor method.
  2. Use comparable surface-reflectance products.
  3. Apply the same cloud and shadow masking logic.
  4. Use similar seasonal windows.
  5. Check acquisition geometry and cloud cover.
  6. Align the grids.
  7. Use consistent output resolution.
  8. Use the same color ramp and class thresholds.
  9. Compare statistics for the same area of interest.
  10. Record all preprocessing steps.

A difference raster can be calculated as:

"NDVI_Later@1" - "NDVI_Earlier@1"

But the interpretation is meaningful only if the two NDVI layers are comparable and invalid pixels are masked in both.

Common NDVI errors and fixes

The result is all black

The renderer may be using an unsuitable min/max range, or the output may be integer rather than floating point. Inspect raster statistics and set Singleband pseudocolor with an appropriate range.

The output contains values above 1 or below -1

Investigate before assuming the formula is wrong. Possible causes include:

  • Incorrect band assignment
  • Unscaled or incorrectly scaled digital numbers
  • Landsat additive offset not applied
  • Negative reflectance values
  • Cloud, shadow, or NoData contamination
  • Different band grids
  • Extreme outliers
  • Invalid denominator handling

A theoretical range check is a quality-control step, not a reason to blindly clamp the values. Identify and document the cause.

The NDVI map has stripes or seams

Check acquisition overlap, scan-line gaps, mosaicking, resampling, cloud masking, and source-scene differences. Landsat 7 SLC-off gaps and mosaicked scenes require special attention.

Vegetation appears blue or bare soil appears green

Check that NIR and red were not reversed, that the renderer is not inverted, and that the correct sensor band numbers were used.

Sentinel-2 NDVI looks blocky or misaligned

Check whether B04 and B08 were resampled to the same grid, whether a 20 m B8A band was used, and whether the output resolution was intentionally chosen.

The map shows bright clouds as vegetation

Apply the product’s cloud, cirrus, shadow, and snow mask. Do not classify clouds from NDVI alone.

NDVI differs between raw DN and reflectance calculations

Check whether the product has a multiplicative scale only or an additive offset. Sentinel-2 optical DN scaling can cancel in the ratio under compatible conditions, while Landsat Collection 2 surface reflectance requires both its scale and offset to be applied. 3 5

The output has a large background value

Check NoData definitions, zero denominators, cloud masks, and whether the source raster’s fill value was treated as a real measurement.

Memory or processing errors occur

Crop the input to the study area, use a suitable output format and compression, process scenes separately, build a model for repeatable batches, or use a virtual raster for exploration before writing the final result.

Validate the NDVI output

Numerical checks

Use raster statistics or a histogram to check:

  • Minimum and maximum
  • Mean and median
  • NoData count
  • Percentage of pixels outside expected bounds
  • Distribution within known land-cover classes

Spatial checks

Inspect known locations:

  • Dense vegetation
  • Bare soil
  • Open water
  • Urban surfaces
  • Snow or cloud areas
  • Forest edge or mixed pixels

Cross-check with the source image

Display a true-color or false-color composite beside the NDVI. Healthy vegetation should generally correspond to strong NIR response and red absorption, but boundaries and mixed pixels should be examined at the source resolution.

Field validation

Where a study makes claims about crop health, biomass, or stress, compare NDVI with field observations or independent measurements. A GPS point alone does not validate vegetation condition; it identifies a location that must be matched to the imagery date, pixel size, and observation protocol.

Export and document the result

Save the NDVI raster as a floating-point GeoTIFF and preserve:

  • Sensor and product name
  • Acquisition date
  • Red and NIR band names
  • Formula
  • Scale and offset treatment
  • CRS
  • Pixel size
  • Resampling method
  • Cloud and shadow mask
  • NoData value
  • Output data type
  • QGIS version
  • Processing date
  • Area-of-interest boundary

Exporting a PNG or JPEG creates a visual product, not a replacement for the analytical NDVI raster. Keep the GeoTIFF for analysis and generate a map layout or image separately for reports.

Reproducible QGIS workflow

For a repeatable project, organize files like this:

ndvi-project/
├── source/
│   ├── red/
│   ├── nir/
│   └── qa/
├── processed/
│   ├── aligned_red.tif
│   ├── aligned_nir.tif
│   └── ndvi_mask.tif
├── outputs/
│   ├── ndvi_YYYYMMDD.tif
│   └── ndvi_YYYYMMDD.png
├── qgis/
│   └── ndvi-project.qgz
└── notes/
    └── processing-notes.md

Keep the Raster Calculator expression in the project notes or processing history. If the source layer names change, reinsert the band references from the QGIS Raster Calculator rather than relying on an old expression.

Frequently asked questions

What is the NDVI formula?

NDVI is (NIR - Red) / (NIR + Red). The correct red and NIR bands depend on the sensor.

Which Landsat bands are used for NDVI?

Landsat 4–7 use Band 4 as NIR and Band 3 as red. Landsat 8–9 use Band 5 as NIR and Band 4 as red. 2

Which Sentinel-2 bands are used for NDVI?

The common Sentinel-2 pair is B08 for NIR and B04 for red. Both are 10 m in the cited Sentinel-2 documentation. B8A is a different 20 m narrow-NIR band and should not be substituted without documenting the methodology. 3

Can I calculate NDVI from raw digital numbers?

Sometimes, but it depends on the product’s scaling and offsets. A common multiplicative scale factor cancels in the ratio, but an additive offset does not. Read the product metadata and apply the documented scale and offset before calculating NDVI.

Do I need atmospheric correction?

For quantitative comparison across dates or locations, use an appropriate surface-reflectance product or documented correction workflow. Atmospheric effects can influence the red and NIR values and therefore the index.

Why does NDVI range from -1 to 1?

The normalized difference formula is theoretically bounded by -1 and +1 for non-negative inputs with a nonzero denominator. Invalid pixels, scaling mistakes, negative reflectance, and numerical issues can produce values outside that expected range and should be investigated.

What does an NDVI value of 0.7 mean?

It often indicates relatively strong green vegetation, but the meaning depends on the sensor, vegetation type, soil, season, canopy density, and preprocessing. Do not use 0.7 as a universal health threshold.

How do I remove clouds from NDVI in QGIS?

Use the quality-assurance or scene-classification band supplied with the imagery. Create a valid-pixel mask from the product-specific classes or bit flags, then set invalid pixels to NoData before or after calculating NDVI.

Should I use B8 or B8A for Sentinel-2 NDVI?

B08 is the common 10 m NIR choice paired with B04. B8A is a 20 m narrow-NIR band with different spectral characteristics. Use B8A only when the project methodology requires it and after intentionally aligning the grids.

What output format should I use?

Use a floating-point GeoTIFF for the analytical result. Use PNG, JPEG, or PDF only for visual presentation or map export.

Can I calculate NDVI for a time series?

Yes, but use comparable products, dates, masks, grids, resolutions, and preprocessing. A time series should use consistent methods and document scene-level differences.

Can NDVI identify crop disease?

NDVI can show changes in vegetation greenness that may be consistent with stress, but it cannot identify disease by itself. Combine it with field observations and other evidence.

Conclusion

QGIS Raster Calculator makes NDVI accessible: load the red and NIR bands, enter the normalized-difference expression, save a floating-point output, and style the result. The scientific quality of the map, however, depends on the preparation behind the formula.

Verify band assignments for the sensor, align the input grids, apply the correct scale and offset, mask clouds and invalid pixels, handle NoData and zero denominators, and interpret values within their environmental and temporal context. A carefully documented NDVI workflow is much more reliable than a visually attractive map created from unverified bands.

References

[1] NASA Earthdata: Normalized Difference Vegetation Index

[2] USGS: Landsat Normalized Difference Vegetation Index

[3] Copernicus Data Space: Sentinel-2 L2A bands and units

[4] QGIS User Guide: Raster Calculator

[5] USGS: Landsat Level-2 science-product scale factors

Leave a Reply

Gabby Jones

Typically replies within a minute

Hello, Welcome to the site. Please click below button for chating me throught WhatsApp.