The demographic history of Scotland includes all aspects of population history in what is now Scotland. Scotland may have been first occupied in the last interglacial period (130,000–70,000 BC), but the earliest surviving archaeological evidence of human settlement is of Mesolithic hunter-gatherer encampments. These suggest a highly mobile boat-using people, probably with a very low density of population. Neolithic farming brought permanent settlements dating from 3500 BC, and greater concentrations of population. Evidence of hillforts and other buildings suggest a growing settled population. Changes in the scale of woodland indicates that the Roman invasions from the first century AD had a negative impact on the native population.
There are almost no written sources from which to reconstruct the demography of early medieval Scotland. This was probably a high fertility, high mortality society, similar to developing countries in the modern world. The population may have grown from half a million to a million by the mid-fourteenth century when the Black Death reached the country. It may then have fallen to as low as half a million by the end of the fifteenth century. Roughly half lived north of the River Tay and perhaps 10 per cent in the burghs that grew up in the later medieval period. Inflation in prices, indicating greater demand, suggests that the population continued to grow until the late sixteenth century, when it probably levelled off. It began to grow again in the relative stability of the late seventeenth century. The earliest reliable evidence suggests a population of 1.2 million in 1681. This was probably reduced by the " seven ill years" of the 1690s, which caused severe famine and depopulation, particularly in the north. The first national census was conducted in 1755, and showed the population of Scotland as 1,265,380. By then four towns had populations of over 10,000, with the capital, Edinburgh, the largest with 57,000 inhabitants.
Overall the population of Scotland grew rapidly in the late eighteenth and nineteenth centuries. Whilst the Lowland Clearances caused depopulation in the affected areas, only local net population reductions occurred in the Highlands during the Highland Clearances. [a] By 1801, Scotland's population had reached 1,608,420 and it grew to 2,889,000 in 1851 and 4,472,000 in 1901. By the beginning of the twentieth century, one in three lived in the four cities of Glasgow, Edinburgh, Dundee and Aberdeen. Glasgow emerged as the largest city, with a population of 762,000 by 1901, making it "the Second City of the Empire". Despite industrial expansion there were insufficient jobs and between the mid-nineteenth century and the Great Depression about two million Scots emigrated to North America and Australia, and another 750,000 to England. The Scots were only 10 per cent of the British population but they provided 15 per cent of the national armed forces, and eventually accounted for 20 per cent of the dead in World War I (1914–18). With the end of mass migration, the population reached a peak of 5,240,800 in 1974. Thereafter it began to fall slowly, moving down to 5,062,940 in 2000. There was also a decrease in some urban populations as a result of policies of slum clearance, overspill and relocation to new towns, with the population of Glasgow falling from over a million in 1951 to 629,000 in 2001. Rural areas also saw a loss of population, particularly in the Highlands and Hebrides.
At times during the last interglacial period (130,000– 70,000 BC) Europe had a climate warmer than today's, and early humans may have made their way to what is now Scotland, though archaeologists have found no traces of this. Glaciers then scoured their way across most of Britain, and only after the ice retreated did Scotland again become habitable, around 9600 BC.  Mesolithic hunter-gatherer encampments formed the first known settlements, and archaeologists have dated a site near Biggar to around 8500 BC.  Numerous other sites found around Scotland build up a picture of highly mobile boat-using people making tools from bone, stone and antlers, probably with a very low density of population. 
Neolithic farming brought permanent settlements, such as the stone house at Knap of Howar on Papa Westray dating from 3500 BC, and greater concentrations of population. Although the Roman geographer Ptolemy indicated that there were 19 "towns" in Caledonia, north of the Roman province of Britannia, no clear evidence of urban settlements has been found and these were probably hillforts.  There is evidence of over 1,000 such forts, most south of the Clyde-Forth line, but the majority seem to have been abandoned in the Roman period.  There is also evidence of distinctive stone wheelhouses (a type of roundhouse, with a circle of stone piers resembling the spokes of a wheel)  and over 400 small underground souterrains (underground galleries that may have been used to store food).  Extensive analyses of Black Loch in Fife indicate that arable land spread at the expense of forest from about 2000 BCuntil the time of the Roman advance into lowland Scotland in the first century AD, suggesting an expanding settled population. Thereafter, there was regrowth of birch, oak and hazel for some 500 years, suggesting that the Roman invasions had a negative impact on the native population. 
There are almost no written sources from which to reconstruct the demography of early medieval Scotland. Estimates have been made of a population of 10,000 in Dál Riata and 80–100,000 for Pictland, which was probably the largest region.  It is likely that the fifth and sixth centuries saw higher mortality rates due to the appearance of bubonic plague, which may have reduced the population.  The examination of burial sites for this period, such as that at Hallowhill, St Andrews, indicates a life expectancy of only 26 to 29.  The known conditions have been taken to suggest it was a high fertility, high mortality society, similar to developing countries in the modern world, with a relatively young demographic profile, and perhaps early childbearing, and large numbers of children born to each woman (although with high child mortality). This would have meant a relatively low ratio of available workers to the number of mouths to feed, which in turn would have made it difficult to produce a surplus that would allow demographic growth and the development of more complex societies. 
From the formation of the Kingdom of Alba in the tenth century, to before the Black Death reached the country in 1349, estimates based on the amount of farmable land suggest that the population may have grown from half a million to a million.  Growth was probably punctuated by occasional crises, like the famines recorded in chronicles for 1154 and 1256. More significant was a series of poor harvests that affected Scotland and most of Europe in the early fourteenth century and widespread famines in 1315–16 and in the later 1330s. 
Although there is no reliable documentation of the demographic impact of the Black Death in Scotland, there are some indications of the immediate effects of the plague. Walter Bower recorded that 24, about a third, of the canons of St. Andrews died during the outbreak.  There are also anecdotal references to abandoned land in the following decades. If the pattern followed that in England, then the population may have fallen to as low as half a million by the end of the fifteenth century.  Compared with the distribution of population after the later Clearances and the Industrial Revolution, these numbers would have been relatively evenly spread over the kingdom, with roughly half living north of the River Tay. 
Price inflation, which generally reflects growing demand for food, suggests that the population was probably still expanding in the first half of the sixteenth century.  Almost half the years in the second half of the sixteenth century saw local or national scarcity, necessitating the shipping of large quantities of grain from the Baltic. Distress was exacerbated by outbreaks of plague, with major epidemics in the periods 1584-8, 1595 and 1597–1609.  The population expansion probably levelled off after the famine of the 1590s, as prices were relatively stable in the early seventeenth century.  Famine was common, with four periods of famine prices between 1620 and 1625. The invasions of the 1640s had a profound impact on the Scottish economy, with the destruction of crops and the disruption of markets resulting in some of the most rapid price rises of the century, but population probably expanded in the Lowlands in the period of stability that followed the Restoration in 1660.  There is evidence that there was a different demographic regime operating in the Highlands, where growth probably continued from the early seventeenth century to the late eighteenth century. 
Estimates based on hearth tax returns for 1691 indicate a population of around 1.2 million. The population may have been seriously affected by the failed harvests (1695, 1696 and 1698-9) known as the " seven ill years".  The result was severe famine and depopulation, particularly in the north. Starvation probably killed 5 to 15 per cent of the Scottish population, but in areas like Aberdeenshire death rates reached 25 per cent.  The famines of the 1690s were seen as particularly severe, partly because famine had become relatively rare in the second half of the seventeenth century, with only one year of dearth (in 1674), and the shortages of the 1690s were the last of their kind.  Between 1650 and 1700 approximately 7,000 Scots migrated to America, 10–20,000 to Europe and England and 60–100,000 to Ireland.  The first reliable figure for the national population is from the census conducted by the Reverend Alexander Webster in 1755, which showed the inhabitants of Scotland as 1,265,380 persons. 
Unlike in England, where the nucleated village existed relatively early, most of the early modern population of Scotland, in both the Lowlands and Highlands, was housed in small clachans or townships and isolated dwellings. These were unstructured groups of houses, often belonging to between four and six tenants, who were often engaged in common agriculture.   As the population expanded, some of these settlements were subdivided to create new clachans and more marginal land was settled, with sheilings (clusters of huts occupied while summer pasture was being used for grazing) becoming permanent settlements. 
Perhaps 10 per cent of the population lived in the burghs that had grown up in the later medieval period, mainly in the east and south of the country. They perhaps had an average population of 2,000, but many were much smaller than 1,000, and the largest, Edinburgh, probably had a population of over 10,000 at the beginning of the period.  Edinburgh doubled in size in the century after 1540, particularly after the plague of 1580, with most of its population probably coming from a growing reservoir in the surrounding countryside.  It also expanded beyond the city walls in suburbs at Cowgate, Bristo and Westport  and by 1750, with its suburbs, it had reached a population of 57,000. The only other towns above 10,000 by the end of the period were Glasgow with 32,000, Aberdeen with around 16,000 and Dundee with 12,000.  By 1600 Scotland had a higher proportion of its population living in larger towns than contemporaneous Scandinavia, Switzerland and most of Eastern Europe:  by 1750 in Europe, only Italy, the Low Countries and England were more urbanised than Scotland. 
The agricultural revolution changed the traditional system of agriculture which had existed in Lowland Scotland. Thousands of cottars and tenant farmers migrated from farms and smallholdings to the new industrial centres of Glasgow, Edinburgh and northern England.  Particularly after the end of the boom created by the Revolutionary and Napoleonic Wars (1790–1815), Highland landlords needed cash to maintain their position in London society. Whereas rents had often been paid in kind, the landlords turned to money rents. They evicted the farmers who had occupied run rig arable land and shared grazing. Their holdings were let to large scale sheep farmers, who could afford substantially higher rents. The eviction of tenants went against dùthchas, the principle that clan members had an inalienable right to rent land in the clan territory. Particularly in the north and west Highlands, estates offered alternative accommodation in newly established crofting communities, with the intention that the resettled tenants worked in fishing or the kelp industry. These evictions were the first phase of the Highland Clearances. The total population of the Highlands continued to rise throughout the clearances.  The result was a continuous exodus from the land—to the cities, and further afield to England, Canada, America and Australia.  The Great Famine of Ireland of the 1840s, caused by potato blight, which devastated the population of Ireland, reached the Highlands in 1846. The overcrowded crofting communities were highly dependent on the potato. Although 150,000 people faced disaster, they were rescued by an effective emergency relief system that stands in dramatic contrast to the failures of relief in Ireland and prevented a major demographic crisis. 
By the time of the first decadal census in 1801, the population was 1,608,420. It grew steadily in the nineteenth century, to 2,889,000 in 1851 and 4,472,000 in 1901.  While population fell in some rural areas, it rose rapidly in the towns. Aberdeen, Dundee and Glasgow grew by a third or more between 1755 and 1775 and the textile town of Paisley more than doubled its population.  Because of the industrial revolution, Scotland was already one of the most urbanised societies in Europe by 1800.  In 1800, 17 per cent of people in Scotland lived in towns of more than 10,000 inhabitants. By 1850 it was 32 per cent and by 1900 it was 50 per cent. By 1900 one in three of the entire population were in the four cities of Glasgow, Edinburgh, Dundee and Aberdeen. Glasgow emerged as the largest city. Its population in 1780 was 43,000, reaching 147,000 by 1820; by 1901 it had grown to 762,000. This was due to a high birth rate and immigration from the countryside and particularly from Ireland; but from the 1870s there was a fall in the birth rate and lower rates of migration and much of the growth was due to longer life expectancy.  Glasgow was now one of the largest cities in the world, and it became known as "the Second City of the Empire" after London. 
Mortality rates were high compared with England and other European nations. Evidence suggests a national death rate of 30 per 1,000 in 1755, 24 in the 1790s and 22 in the early 1860s. Mortality tended to be much higher in urban than rural settlements. The first time these were measured, 1861–82, in the four major cities these were 28.1 per 1,000 and 17.9 in rural areas. Mortality probably peaked in Glasgow in the 1840s, when large inflows of population from the Highlands and Ireland combined population outgrowing sanitary provision and combining with outbreaks of epidemic disease. National rates began to fall in the 1870s, particularly in the cities, as environmental conditions improved. By 1930–32 the national rate was 13.4 per 1,000, with a rate of 14.1 and in rural areas 12.8. 
Even with the growth of industry there were not enough good jobs: as a result, from 1841 to 1931, about two million Scots emigrated to North America and Australia, and another 750,000 Scots relocated to England.  With a population of 4.8 million in 1911, Scotland sent 690,000 men to the First World War, of whom 74,000 died in combat or from disease, and 150,000 were seriously wounded.   Thus, although Scots were only 10 per cent of the British population, they made up 15 per cent of the national armed forces and eventually accounted for 8.3% of the UK's 887,858 dead from all causes.  While emigration began to tail off in England and Wales after the First World War,  it continued apace in Scotland, with 400,000 Scots, 10 per cent of the population, estimated to have left the country between 1921 and 1931.  When the Great Depression hit in the 1930s there were no easily available jobs in the US and Canada, and emigration fell to less than 50,000 a year, bringing to an end the period of mass migrations that had opened in the mid-eighteenth century.  This contributed to the growth of the population, which reached a peak of 5,240,800 in 1974. Thereafter it began to fall slowly, moving down to 5,062,940 in 2000. There was also a decrease in some urban populations as a result of slum clearance, overspill and relocation to new towns, with the population of Glasgow falling from over a million in 1951 to 629,000 in 2001. Rural areas also saw a loss of population, particularly the Highlands and Hebrides.  In the early part of the twenty-first century Scotland saw a rise in its population to 5,313,600 (its highest ever recorded) at the 2011 census.