Generally inflation and CPI are reported on a national level. If a country for example has 10 cities, after surveying prices in each individual city, how is the total CPI number determined for the national level? The cities may have very different living costs and population sizes, how is this taken into account when aggregating to a single CPI value?
Yes, the data is weighted based on the population size of the area from which it came. The survey designers employ a method called stratified random sampling, which ensures that the prices of goods selected for the sample are distributed across all areas (rather than by chance landing up concentrated in a few areas). Then, the prices in each stratum are assigned a sampling weight, the ratio of size of the population in that stratum to the number of prices collected in that stratum. Those weights are used when calculating the mean price for that item (i.e. multiply each observation by its weight, divide by the sum of the sampling weights).
Further, a representative basket of goods and services is used (which was found through household surveys, again with random sampling), and the estimated mean prices of goods are plugged in to that basket to get an overall index of price. The basket should thus be the same across all years in order for the price index to be comparable across years (except when using a chained price index).