Castles originated around the 9th and 10th centuries, the first was built by William the Conqueror of Normandy in 1066, and he built 9 castles in London.
The first one of them was Windsor Castle; it has been inhabited since it was built in the XI century. Windsor Castle is reputed to be the largest inhabited castle in the world although the largest castle is Prague Castle; some bigger castles took up to 20 years to complete although most took around 15 years.
Castle were primarily built to house Kings and lords and therefore the bigger the castle the more power the king or lord had, and were manly used as fortification to protect a territory against an invasion.
They were very effective, a lot castles had an enormous amount of food stored in them, Some castles had farms in the grounds, to help keep the population fed in the case of a siege bigger Castles even had a well inside.
Some castle had up to thousands of peasants living in them, a lot of castles were built on a Motte this was a mound of earth with a flat top and where the excavation of earth to make the motte was would leave a ditch around and was often fill with water, (A moat) this acted as a further defence against the invading forces. And after a time the moats became more and more elaborate and included a drawbridge and portcullis
The best way of destroying the castle wall was gunpowder
If a siege didn’t work a castle could be destroyed by digging beneath a wall making a tunnel, then the tunnel would be destroyed and so walls damaging the wall, however the best way of destroying the castle wall was gunpowder and with the introduction of gunpowder, castles proved to be useless.
Even the mightiest of castles was no match against the cannon. I have two castle near where I live in the south of England Arundel of which you can see in the picture and another is Amberley which is now a Luxury hotel, also within a short drive we have Bodiam and Lewes Castles , Pevensey, Hastings and Herstmonceux pronounced (hers mon sue)