This photo shows part of medieval wall defences of Great Yarmouth. As a coastal town on the North Sea, Yarmouth was part of England's frontier defences. Not only was it one of the major suppliers of a maritime defence force, before a permanent royal navy was created, but it also had to be prepared to face attack from the sea. The cost of building defensive fortifications was, however, beyond the normal fiscal resources of the medieval borough and so the task was undertaken piecemeal, over the course of the thirteenth to fifteenth centuries.
About a quarter of England's medieval boroughs are known to have had some kind of defensive fortifications. Some originated in Roman or Saxon times, but most (putting aside castles built by kings or lords of towns, which were as much to administer and control the towns as to protect the local populace) stone defences were built during the Late Middle Ages. The motivations for building town walls were various. Obviously, one primary concern was protection in a time when society was ruled by a warrior-caste: both civil wars and threats of foreign invasion provided impetus to particular bouts of wall-building. However, towns rarely built their walls along a perimeter chosen for its defensibility some wall perimeters were not at all practical from that perspective. Motivation was also a matter of defining, or laying claim to, jurisdiction over areas within the perimeter; of facilitating the collection of tolls, by obliging commercial goods to come in, or leave, the town by a limited number of set entrances/exits (in some towns stone gates were the first step towards converting earthworks to a stone perimeter); as well they expressed the dignity, status and indépendantisme of the borough community.
Further information of Yarmouth's walls may be found on this site in the History of medieval Yarmouth section and on the Yarmouth plan page, and externally in Palmer's Perlustration of Great Yarmouth and Graham Woodcock's site on Yarmouth history.