We're all accustomed to regarding the census for Scotland starting in 1841, and whilst it's true that this is the first detailed census useful for most people's family history, there were censuses before that, for example, various parishes in 1835, for Jedburgh in 1821, for Hutton in 1811 and Stow in 1801, and Portpatrick in 1763.
I was astonished to see a BBC article about Scotland's first census occurring in the 7th century. It's called Senchus fer nAlban (History of the men of Scotland) and it's Scotland's earliest census. It is a list of the population of Dál Riata, the kingdom of the Gaels on the west coast of Scotland, in Lorn and the islands of Islay and Jura.
I assume that it's written in classical Irish, the forerunner of modern Irish and Scottish Gaelic. There's much more in the BBC article including a picture, and a video in Scottish Gaelic which has some English subtitles, for example "Eogan Garbh has 30 houses, his wife is Crodu, daughter of Dallan, son of Eogan, son of Niall".