Scottish castles are buildings that combine fortifications and residence, built within the borders of modern Scotland. Castles arrived in Scotland with the introduction of feudalism in the twelfth century. Initially these were wooden motte-and-bailey constructions, but many were replaced by stone castles with a high curtain wall. During the Wars of Independence, Robert the Bruce pursued a policy of castle slighting. In the late Middle Ages new castles were built, some on a grander scale as "livery and maintenance" castles that could support a large garrison. Gunpowder weaponry led to the use of gun ports, platforms to mount guns and walls adapted to resist bombardment.
Many of the late Medieval castles built in the borders were in the form of tower houses, smaller pele towers or simpler bastle houses. From the fifteenth century there was a phase of Renaissance palace building, which restructured them as castle-type palaces, beginning at Linlithgow. Elements of Medieval castles, royal palaces and tower houses were used in the construction of Scots baronial estate houses, which were built largely for comfort, but with a castle-like appearance. In the seventeenth and eighteenth centuries the military significance of castles declined, but they increasingly became tourist attractions. Elements of the Scots Baronial style would be revived from the late eighteenth century and the trend would be confirmed in popularity by the rebuilding of Balmoral Castle in the nineteenth century and its adoption as a retreat by Queen Victoria. In the twentieth century there were only isolated examples of new castle-influenced houses. Many tower houses were renovated, and many castles were taken over by the National Trust for Scotland or Historic Scotland and are open to the public.