The National Records of Scotland’s figures provide a breakdown of the population into almost 7000 small areas, known as data zones.
Overall more than half of the data zones in every council area increased in median age, reflecting the overall ageing of Scotland’s population.
Denise Patrick, head of population and migration statistics, said: “In the last decade, mainly rural councils, as well as those in the west of Scotland, have seen a higher proportion of their areas decrease in population.
“During the same time, cities have seen more areas increase in population.
“Many small geographical areas change in population over time. There is often many reasons for this including births and deaths, as well as migration.
“Larger changes may be due to housing demolitions or new housing developments.
“The data zone with the highest population, as of June 2019, was Currie West in Edinburgh, with 3784 people.
“This area contains student accommodation for Heriot-Watt University which helps explain the high number.”
Scotland’s total population is the highest its ever been at 5.46 million but, according to Economy Secretary Fiona Hyslop, there are challenges.
She said: “Against a backdrop of a record low in the birth rate, Scotland’s population is ageing. It is welcome that people are living longer.
“However, many local communities have experienced population decline, particularly in rural areas and parts of the west of Scotland.
“With all of Scotland’s population growth predicted to come from migration, the impact of Brexit means that, in the future, we may not have enough people of the right ages in the right places.
“The Scottish Government has established a task force to address population concerns with the aim of making communities across Scotland attractive places to live, work and bring up families.”