Medieval fortification
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.

Killing fields: A killing field was an area between the main wall and a secondary wall, so when the first wall was breached the attackers would run into the killing field to be confronted by another wall from which soldiers bombarded them. Soldiers would be positioned atop the second wall and armed with any variety of weapons, ranging from bows to crossbows to simple rocks.

Moats: A moat was a common addition to medieval fortifications, and the principal purpose was to simply increase the effective height of the walls and to prevent digging under the walls. In many instances, natural water paths were used as moats, and often extended through ditches to surround as much of the fortification as possible. Provided this was not so unnaturally contrived as to allow an attacker to drain the system, it served two defensive purposes. It made approaching the curtain wall of the castle more difficult and the undermining of the wall virtually impossible. To position a castle on a small island was very favorable from a defensive point of view, although it made deliveries of supplies and building materials more cumbersome and expensive.

Keeps: A keep is a strong central tower which normally forms the heart of a castle. Often the keep is the most defended area of a castle, and as such may form the main habitation area for a noble or lord, or contain important stores such as the armoury or the main well.

Stairs: Stairs were also constructed to contain trick or stumble steps. These were steps that had different rise height or tread depth from the rest and would cause anyone running up the stairs to stumble or fall, so slowing down the attackers' progress.

Doors: A typical exterior wooden door might be made out of two or more layers of oak planks. The grain of the wood would run vertically on the front layer and horizontally on the back, like a simple form of plywood. The two layers would be held together by iron studs, and the structure might be strengthened and stiffened with iron bands.
The studs themselves were pointed on the front so that attackers would damage their weapons (swords, axes, etc.) while trying to break through.

Transition to modern fortification: From the mid-15th century onwards, the power of cannons grew and medieval walls became obsolete as they were too thin to offer any realistic protection against prolonged bombardment. As a consequence of this, medieval walls were often upgraded with the addition of artillery platforms or bastions, and battlements were replaced by thick parapets with embrasures. In many cases, the medieval walls were dismantled and their stonework, which was still valuable as construction material, was reused in the construction of the new fortifications. The resulting space is often seen in old city centers of Europe even to this day, as broader streets often outline where the old wall once stood (evident for example in Prague and Florence, Italy).
The transition between medieval and early modern fortification can be seen in the fortifications of Rhodes in Greece and the fortifications of Famagusta in Cyprus.

Defensive obstacles: Just as modern military engineers enhance field fortifications with obstacles such as barbed wire, medieval engineers used a number of obstacle types including abatis, caltrops, cheval de frise, and trou de loup.

Siegecraft: Trebuchet
Cannon
Mangonel
Ballista
Catapult

See also: Medieval warfare
Siege engine
Guédelon Castle - from 1996 to 2020 they will build a 13th-century castle exclusively using methods of that time. A lot of information regarding castrametation and castellology had already surfaced thanks to this project.
Star fort replaced medieval fortifications.
Encastellation
Rocca di Manerba del Garda
Castle Site of Montbazon

Notes: These defenses were not only used as counter-measures against siege engines and were effective defenses against many other forms of attack including the dispatchment of attackers unshielded by siege engines.

References: 

Bibliography: Toy, Sidney. (1985) Castles: Their Construction and History. ISBN 978-0-486-24898-1.