The figure for Barcelona is incorrect. The data that you took from citypopulation is the population of the province, not the municipality (which would be around 1 million) or the metropolitan area (around 2 million). The fact that the city and the province have the same name may lead to confusion.