# Differences in Area calculation methods Google Earth Engine?

I calculated the area of my river basin twice and got different results and do not know why/what exactly happens.

At first, I just wanted to have the whole area of my river basin, which I did by:

``````//calculating area whole basin
var areabasin = ee.Image.pixelArea().divide(1000000).reduceRegion({
reducer: ee.Reducer.sum(),
geometry: shape_basin,
scale: 120,
maxPixels: 1e13
});
print('Area of the whole basin: ', areabasin);
``````

shape_basin is a shapefile I uploaded as an asset that covers the area of interest. As a result, I got 580,453, which I assume must be in km2 as ee.Image.pixelArea is calculating it in m2 and I divided it by 1.000.000 Later, I classified this area and calculated the area of the individual classes. This I did by:

``````// calculating the areas by class

var classes = result.select('classband');
var area = ee.Image.pixelArea().divide(1000000);

//water

//crops

//urban

//bare

//forest

//calculating the area of the waterclasses

var areas = area_image.reduceRegion({
reducer:ee.Reducer.sum(),
geometry: shape_basin,
scale: 120,
maxPixels:1e13
});
print(areas);
``````

As a result for the five classes, I get:

``````bareland: 769703.0088548877
cropland: 421111.16084957926
forest:   505036.9907116392
urban:    163561.49438641773
water:     21118.550734309763
``````

Which results when added up in 1,880,531, or multiplied by 120 (scale), it results in 225,663,745.

Any ideas why the difference is so big? How could I change this, what am I doing wrong?

The problem you're having is that you're multiplying pixelArea * class. so, for instance, barearea is off by a factor of 4 since it's class 4 (you probably wanted to multiply the mask by area, not mask the image and multiply that).

``````var waterMask = classes.eq(1);
``````var areas = area.addBands(classes).reduceRegion({