Feudalism developed in Western Europe following the decline of Charlemagne's empire in the 9th century. Under feudalism, society was organized into a pyramid-like hierarchy with the king at the top granting land to nobles in exchange for loyalty and military service. Nobles then granted land to knights who granted land to peasants, who lived on and worked the land in exchange for protection. Peasants had little freedom and lived difficult lives, but their servitude was tied to the land rather than being slaves. The feudal system helped provide security and governance in a decentralized political environment vulnerable to invaders.