More people are moving to Scotland every year than leaving
The population of Scotland reached its highest level in a generation last year, according to the latest figures.
Registrar General for Scotland, Duncan Macniven, said the population was 5,194,000 in the middle of last year.
This represented a rise of 25,500 on the previous year, and the highest total since 1979.
Mr Macniven said migration accounted for most of the increase, while there were also about 4,600 more births than deaths.
Over the year, 45,400 people came to Scotland from England, Wales and Northern Ireland - fewer than in the previous year - while 41,300 left Scotland to go in the opposite direction.
But about 42,700 people, including asylum seekers, came from overseas and only 25,200 went in the opposite direction, giving a net gain of about 17,500 people - the highest net gain from overseas migration since current records began in 1991-92.
Other changes, including variations in the prison population and changes in the number of armed forces stationed in Scotland, amounted to a decrease of 800 people.
"Scotland's population has reached a level not seen since the late 1970s," Mr Macniven said.
"The increase in the year ending in June 2009 was 25,500, which was slightly greater than the previous year's 24,300.
"Migration accounted for most of the increase although, at 21,700, it was less than the record 27,000 net migration in 2006-07."
A spokesman for the Scottish government said it welcomed the population rise as a "key contributor to sustainable economic growth".
He added: "It is excellent news that Scotland's population has increased to its highest level since 1979. Our rate of population growth has moved significantly closer to that of many other European nations."
Scotland's highest ever population was 5.25 million in 1974.
It had fallen to about 5.05 million by 2002 but has since risen again due to migration and a higher birth rate.
Aberdeen had the largest population increase last year, with 1.6%, followed by Edinburgh, with 1.3%, and Perth and Kinross, with 1.2%.
Inverclyde had the largest population decrease, with 0.7%, followed by Argyll and Bute, on 0.5%, and North Ayrshire, with 0.3%.
Figures for Dumfries and Galloway and the Scottish Borders were almost unchanged.
Scotland has, on average, 67 people per square kilometre, ranging from nine per square kilometre in Eilean Siar and Highland Council areas to 3,353 persons per square kilometre in Glasgow.