Before the X century, villagers had to rely heavily on walls and rivers to stop an invading army's progression. Walls were commonly built. Nevertheless, as time passed; people realized that walls were not as effective as they used to be because of new weapons and siege engines. William the Conqueror changed history when he conquered Great Britain in 1066. Having built more than 40 castles across England, William's belief was that by building numerous castles in key-spots, Great Britain would be able to easily repel foreign invasions mainly from the Vikings and the French. Even though invasions still continued, he was successful in stopping most of them. Soon afterwards, castles were built in every major European country because they provided a notorious advantage for the defenders.
Originally as a means of defense, castles were also meant to increased the power of a king or lord throughout the kingdom. When William the conqueror was Great Britain's king, his most notorious fortress was The Tower of London. Building it took more than 20 years and it can still be seen today. He built it, mostly, to show English citizens his supreme rule over England.
A town consisted of farmland, a chapel and a castle. In the Dark Ages, feudalism was a very common practice. Serfs worked for lords who in exchange worked for the king. The king offered protection to the serfs who paid taxes to their lords who protected the king. It was all a trade which benefited all but the serfs.
As the population grew, and more protection was needed, stronger and bigger castles were built. Earlier castles were made of timber and earth which made them very weak and flammable. Years later, stone was gradually incorporated and older castles were rebuilt with stone. Most castles took an average of 10-15 years to complete.
Castles were very effective from the X to the XV century. Castles notoriously changed the course of history since warfare was different than before. An open-field battle was very rare making conquering new land harder than before; thus the change of epoch was evident: the Dark Ages.
In 1346 came the Battle of Crecy; the first of the Hundred Years War between France and England. For the first time ever, cannon fire was used in open country against a castle. It was evident that even the mightiest of castles would prove to be useless against such devastating weapons. Castle walls were not enough to protect its inhabitants anymore. For this reason, new improvements for castles were idealized.
When castles stopped being effective for defensive purposes, many lords, nobles and kings destroyed them to make themselves a palace with the newly-acquired stone and land. Many castles were rebuilt whilst others were totally demolished.
Even though many castles have been destroyed throughout the centuries, many can be seen today. In fact, some are so well preserved that it can be easily seen how they were 500 years ago! Nevertheless, more than half of the once-existing castles are gone by today.
Thousands of castles still exist, out of which the most remarkable are English, French, German, Irish, Italian, Scottish and Spanish
Attacking a castle was extremely difficult and could only be achieved after much preparation and with siege engines capable of destroying it (if chosen to). On the other hand, defending a castle was not so difficult but was more often deadly for the defenders who had almost no control over the situation and were forced to wait for relief. However, they often fought against the invaders from the castle's interior and building traps was very common to kill as many invaders as possible.
In the interim, inhabiting a castle was very difficult. Castles were not as luxurious as we imagine and life inside a castle was very undesirable. Acquiring food and maintaining it involved the work of hundreds or thousands of peasants and even then - it would often spoil spreading disease to a complete castle. Water was also difficult to replenish for some castles did not have a well and water had to be brought from the exterior.
Fortunately, it wasn't continuously undesirable inside a castle. There was plenty of entertainment to be had and kings very frequently celebrated with enormous feasts for almost any reason they pleased. Ches was new in the Medieval Times and as time passed it became much more popular - and chess wasn't the only board game played - there were many more.
Housing inside a castle was important because it was required by law in most castles that everyone had to have a place to live. Of course houses were common outside of the castle's wall as well. Unfortunately, the poor very frequently lived in a hut which was very seldom, if at all, cleaned. This led to many diseases which were spread throughout Europe making medieval health a topic of concern for the king - reason for which many doctor schools were opened and the church lost much of its power because of its unavailability to cure diseases.
Due to such conditions, many thieves existed inside a castle. To avoid them, the king set many standars and laws in which anyone who disobeyed was to be tortured or executed.
However, castles evolved throughout the years as it can be noted in the Medieval Timeline.