Medieval fortification
Fortification types: 

Archer towers: Towers of medieval castles were usually made of stone, wood or a combination of both (with a stone base supporting a wooden loft). Often toward the later part of the era they included battlements and arrow loops. Arrow loops were vertical slits in the wall through which archers inside shot arrows at the attackers, but made it extremely difficult for attackers to get many arrows back through at the defenders.

Siege Defenses: Sieges were common during the Middle Ages and because of this many cities fortified their walls and castles to defend against the use of siege engines by their attackers1. Many cities utilized catapults that would hurl stones and other missiles at enemy siege engines and soldiers. The most commonly used catapult for defense was the trebuchet, a torsion powered catapult that dominated the Middle Ages both offensively and defensively. The trebuchet was known for its considerable force but required a longer loading time compared to other siege engines, sometimes taking up to an hour, which lead to some cities using catapults such as the mangonel and onager instead, which could put projectiles downrange much faster than the trebuchet. The trebuchet’s destructive force caused engineers to thicken walls, round out towers, and to redesign fortifications so that they could employ trebuchets for defense. The Ayyubids between 1196 and 1218 built towers mounted with massive trebuchets, which hypothetically would use their height advantage to take out opposing siege engines. Ballistas were another type of catapult utilized as a defensive weapon, however they were not often used. This is because their missiles sometimes lacked the force to dismantle enemy siege engines and their immobility confined them to the top of a city's towers were they could easily be taken out by enemy catapults, including offensive ballistas which were usually employed for the very reason of dismantling defenses on the top of towers and keeping defenders off of a wall's battlements. After the invention of cannons near the beginning of 12th century CE, many torsion powered catapults became largely obsolete and cannons became commonplace medieval siege engines by the 15th century. While mostly used for offensive purposes, the first recorded use of a cannon in Europe was to defend the city of Algeciras during the siege of 1343-44. However slow to load, cannons proved to be devastating weapons that could level a city's walls or destroy siege engines with only a single projectile.

City walls: An exact nature of the walls of a medieval town or city would depend on the resources available for building them, the nature of the terrain, and the perceived threat. In northern Europe, early in the period, walls were likely to have been constructed of wood and proofed against small forces. Especially where stone was readily available for building, the wood will have been replaced by stone to a higher or lower standard of security. This would have been the pattern of events in the Five Boroughs of the Danelaw in England.
In many cases, the wall would have had an internal and an external pomoerium. This was a strip of clear ground immediately adjacent the wall. The word is from the late medieval, derived from the classical Latin post murum ("behind the wall").
An external pomoerium, stripped of bushes and building, gave defenders a clear view of what was happening outside and an unobstructed field of shot. An internal pomoerium gave ready access to the rear of the curtain wall to facilitate movement of the garrison to a point of need. By the end of the sixteenth century, the word had developed further in common use, into pomery.
Also by that time, the medieval walls were no longer secure against a serious threat from an army, as they were not designed to be strong enough to resist cannon fire. They were sometimes rebuilt, as at Berwick on Tweed, or retained for use against thieves and other threats of a lower order. Very elaborate and complex schemes for town defenses were developed in the Netherlands and France, but these belong mainly to the post-medieval periods. By 1600, the medieval wall is likely to have been seen more as a platform for displaying hangings and the pomery as a gathering ground for spectators, or as a source of building stone and a site for its use, respectively. However, a few, such as those of Carcassonne and Dubrovnik, survived fairly well and have been restored to a nearly complete state.
Medieval walls that were no longer adequate for defending were succeeded by the star fort. After the invention of the explosive shell, star forts became obsolete as well.

Harbors: Harbors or some sort of water access were often essential to the construction of medieval fortifications. It was a direct route for trading and fortification. Having direct access to a body of water provided a route for resupply in times of war, an additional method of transportation in times of peace, and potential drinking water for a besieged castle or fortification. The concept of rivers or harbors coming directly up to the walls of fortifications was especially used by the English as they constructed castles throughout Wales.
There is evidence that harbors were fortified, with wooden structures in the water creating a semi-circle around the harbor, or jetties, as seen in an artist's reconstruction of Hedeby, in Denmark, with an opening for ships to access the land. Usually, these wooden structures would have small bases at either end, creating a 'watch' and defense platform.

Churches and monasteries: Religion was a central part of the lives of medieval soldiers, and churches, chapels, monasteries, and other buildings of religious function were often included within the walls of any fortification, be it temporary or permanent. A place to conduct religious services was usually essential to the morale of the soldiers.

Mottes and baileys: Motte-and-bailey was the prevalent form of castle during 11th and 12th centuries. A courtyard (called a bailey) was protected by a ditch and a palisade (strong timber fence). Often the entrance was protected by a lifting bridge, a drawbridge or a timber gate tower. Inside the bailey were stables, workshops, and a chapel.
The motte was the final refuge in this type of castle. It was a raised earth mound, and varied considerably, with these mounds being 3 metres to 30 metres in height (10 feet to 100 feet), and from 30 to 90 metres (98 to 295 ft) in diameter. There was a tower on top of the motte. In most cases, the tower was made of timber, though some were also made of stones. Stone towers were found in natural mounds, as artificial ones were not strong enough to support stone towers. Larger mottes had towers with many rooms, including the great hall. Smaller ones had only a watch tower.

Construction: Construction could sometimes take decades. The string of Welsh castles Edward I of England had built were an exception in that he focused much of the resources of his kingdom on their speedy construction. In addition to paid workers, forced levies of labourers put thousands of men on each site and shortened construction to a few years.

Location: Nature could provide very effective defenses for the castle. For this reason many castles were built on larger hills, cliffs, close to rivers, lakes or even caves.

Materials: Materials that were used in the building of castles varied through history. Wood was used for most castles until 1066. They were cheap and were quick to construct. The reason wood fell into disuse as a material is that it is quite flammable. Soon stone became more popular.
Stone castles took years to construct depending on the overall size of the castle. Stone was stronger and of course much more expensive than wood. Most stone had to be quarried miles away, and then brought to the building site. But with the invention of the cannon and gunpowder, castles soon lost their power.

Costs: Costs for the walls depended on the material used. Wood would cost very little and was quick to build, but was weak. Stone was strong but very expensive and time-consuming to construct.

Manpower: Manpower in the medieval era in Europe consisted mainly of serfs.

Walls: The height of walls varied widely by castle, but were often 2.5–6 m (8.2–19.7 ft) thick. They were usually topped with crenellation or parapets that offered protection to defenders. Some also featured machicolations (from the French machicoulis, approximately "neck-crusher") which consisted of openings between a wall and a parapet, formed by corbelling out the latter, allowing defenders to throw stones, boiling water, and so forth, upon assailants below. Some castles featured additional inner walls, as additional fortifications from which to mount a defense if outer walls were breached.

Gates: Any entrance through a wall, being an opening, forms an obvious weak point. To be practical, the entryway would have to accommodate supplies being brought through, yet difficult for attackers to breach. For example, passage over ditches or moats would have to be withdrawn to deny attackers. The use of multiple walls or ditches around an entrance would also make it difficult for defenders to use the entrance practically, necessitating better methods of control. Gates came in many forms, from the simple stone buttress and timber blocks, to the massive and imposing stone archways and thick wooden doors most associated with medieval citadels.