When did the first castles appear in Western Europe? What is the reason for the construction of such powerful fortified

When did the first castles appear in Western Europe? What is the reason for the construction of such powerful fortified structures (indicate at least two reasons)? List the main buildings of the castle and their purpose.

in the 8th century, the first castles appeared in Western Europe
1) Protection from attacks by Normans and Hungarians, 2) protection from enemies, 3) for the status of lord.
Walls that were meant to protect against attacks. The moat, filled with water, protected from foot soldiers. Donjon is the main tower, where the well and food warehouses were located. A spiral staircase was made in it, along which it was possible to descend to the underground passage and leave the castle.

Remember: The process of learning a person lasts a lifetime. The value of the same knowledge for different people may be different, it is determined by their individual characteristics and needs. Therefore, knowledge is always needed at any age and position.