I'm not writing about the history of fortresses since the beginning of the human history. In Mesopotamia, there are entire hills with hundreds of layers of ruins of fortified towns. Castles and fortresses always served two purposes. First, they were for defense, and second they were the seats of local or national rulers. The castles guarded the borders, defended the towns and controlled the marketplaces. Most castles in the Middle Ages were the residences of the local princes. Their task was to defend their peasants, and the peasants’ task was to support their lord and his warriors. When enemies attacked, the peasants fled with their belongings into the castle.
There were two kinds of castles. The best place to build a castle was on a steep hillside, which made it difficult to attack. In the lowlands, castles were built with moats (deep ditches filled with water). The castles on the hills had ditches or moats where they were most accessible, and always at the entrance.
At the entrance of a castle was always a drawbridge. This was not a decoration. The drawbridge normally gave access to the castle over the moat. But when the enemy attacked, the drawbridge was pulled up, as you can see in the picture.
The castles were first built with local building stones, often fieldstones. Later they were built with stone blocks, cut from quarries and, very rarely, of bricks. The historical architectural styles used for castles were those of the Middle Ages generally -- Carolingian, Romanesque and Gothic.
The invention of gunpowder in the 15th century and the development of better cannons made most castles stormable and useless. But until the 19th century, fortresses were still built at strategic locations, but with a different type of design, to resist cannons. But there is actually even a "modern" type of castle. In the romantic period in the 19th century, some kings built castles as memories of old times. The most famous of these new castles are Neuschwanstein and two other ones built by the insane Bavarian "Fairy King” Louis II. They are somewhat dubious buildings, but at least they are made of stones and are not a cream-colored texture. The only pastelle-colored buildings of the era are the Baroque residences of the kings built in the 17th and 18th centuries -- Schloß, in German, as opposed to Burg, which is a real castle. Yes, a real castle may be white and proud, or black and bad, or gray and decrepit, but it is never, never silly and cream-colored!