Castles were fortified structures built across Europe during the Middle Ages for protection from enemies. They were constructed by wealthy nobles and lords to house their families and workers. While initially made from dirt, timber, and stone, castles evolved over 900 years into large fortresses with multiple defenses against sieges. The advent of gunpowder in the 14th century diminished their military effectiveness, leading to the end of widespread castle construction.