Europe saw a massive surge in castle construction between the 9th and 15th centuries primarily due to feudalism and the lack of a centralized government. After the fall of the Carolingian Empire, power was decentralized among local lords who needed fortified residences to protect their land, wealth, and peasantry from rival nobles and invaders like the Vikings or Magyars. Castles served three main functions: they were military fortresses for defense and offensive raids, administrative hubs for governing the local area, and symbols of status that broadcast a lord's power. In regions like Germany, the "Holy Roman Empire" consisted of hundreds of small principalities, leading to a "castle arms race" where every minor noble sought to secure their territory. By the time gunpowder and cannons made traditional stone walls obsolete in the late Middle Ages, tens of thousands of these structures had been built, many of which were later converted into more comfortable, decorative palaces or left as the romantic ruins we see today.