How to calculate the difference between two rasters in QGIS?

I have two similar rasters of the Mount Vesuvius and surroundings: one spans 20 kilometers, and the other one 50 kilometers. The two rasters are overlapping:

What I would like to do is to create a new raster file which will show the difference in elevation between these two rasters. I tried using the Raster calculator with the following expression:

``````"vesuvius_radius_20KM@1" - "vesuvius_radius_50KM@1"
``````

But for some reason it does not work. After I press OK, all I get is some sort of black raster file which does not have any kind of elevation data in it, nor it has any number of pixels:

What am I doing wrong, and how can I create a raster file which will show the difference between the upper mentioned two raster files?

Here are those two raster files:

Oh will you feel silly! ;-)

The result is actually correct:

• The two rasters are identical where they overlap.
• Where they do not overlap, the result is NaN because you cannot do math with a non-existent value.
• Thank you for the quick reply and explanation bugmenot123. I do feel silly. May 7, 2016 at 23:49

I´m not quite sure,if what bugmeont suggested is correct. I guess if both layers are equal the outcome of the new one should be a layer with zeros and not with no-data values.

edit: also yourpicture shows 0 there, where there is no overlap and NaN where you have overlap, which also does not fit to the explanation.

• Hi @Philipp Dahlem. Thank you for the reply. I am not sure I understood the first part of your reply. Can you try to download the both .tif files please? As for the second one: you are correct. It's definitively a bug in QGIS: the 'nan' should be depicted with white rectangle, and '0' should be depicted with black rectangle May 8, 2016 at 16:13
• In modern QGIS there is a range from white to black going from 0 to 0, so the result is slightly more clearly correct. The 0 area is shown in black and the no-data area is transparent (white if the default white map background is used). Oct 4, 2022 at 7:30