A castle is a fortified habitation. The planning and building of castles is primarily directed by the necessities of defense. In the early Middle Ages the principal elements of castles were the keep or donjon and the hall in France and England, the Bergfrid and the Palas in Germany. The keep is a tower spacious enough to act as living quarters in time of war for the lord or governor and the garrison; the Bergfrid is a tower of normal proportions, the Palas is the hall-range. The earliest dated donjon is at Langeais (c. 990), the earliest surviving manor hall at Goslar (mid eleventh century).
England built some hall-keeps, i.e., keeps wider than they are high (Tower of London). In France and Italy in the early 13th century Roman precedent led to symmetrical compositions with angle towers and a gatehouse in the middle of one side. Some castles of Edward I in Britain took this over, and where in the late Middle Ages castles were still needed (south coast, Scottish border), they were often symmetrically composed. The rule in Britain at this time, however, was that castles could be replaced by fortified manor houses. Towards the end of the Middle Ages the spread of firearms changed the castle into the fortress, with low bastions for mounting cannon and no towers.