The castle is a defensive structure with a compact - usually stone or brick - buildings, which is characteristic of medieval Europe, especially in the period of the full (X-XIII century) and late (XIV-XV century) medieval times. The castle served various functions: the seat of royal, ducal or noble power, it could be the "family home" of a single knight, but also a military outpost subordinate to the royal authority. It is assumed that the first "classic" castles in Europe were built in the 9th century, after the fall of the Carolingian state. In many cases - in today's France or Germany - they had the character of the seat of a ruler or a knight and were often only keep, made of stone. These early castles lack many of the later defensive elements, such as towers or an extensive wall system. However, at the turn of the twelfth and thirteenth centuries, there was a significant change and under the influence of the experience of the Crusades, castles evolve, becoming more and more complex. They begin to have one or more rows of walls. In the territory of Poland, castles appeared at the turn of the 12th and 13th centuries, replacing the previous wooden and earth castles, and one of the first such fortresses is the castle in Legnica or the reconstruction of Wawel in Krakow. It is also worth remembering that the Teutonic castles in Pomerania and Livonia were unusual in their own way, because they were built primarily of brick, not stone. A great example of such a castle is, for example, Malbork. The decline of castles dates back to the 15th century, when the popularization of gunpowder made it possible to acquire them relatively quickly.