Salah ad-Din — Saladin — began the fortress in the 1170s, fortifying the high ground between the two existing cities of Fustat and Fatimid Cairo against Crusader attack. Successive dynasties kept adding to it.
Its secret weapon was water: Saladin's engineers cut a spiral well shaft nearly ninety metres down through the rock to the water table, so the fortress could stand a siege. The Well of Joseph survives, and it is one of the great pieces of medieval engineering in Egypt.
The Mosque of Muhammad Ali is far later: built in the first half of the nineteenth century by the Ottoman governor who founded the dynasty that ruled Egypt until 1952. He deliberately built in the Istanbul manner rather than the local Mamluk one, and the choice was political as much as aesthetic.
The same ruler gave the Citadel its darkest scene: in 1811 he invited the Mamluk leadership to a ceremony here and had them killed in the walled descent from the gate — the end of six centuries of Mamluk power in a single afternoon.
The Citadel remained a military installation into the twentieth century, which is why parts of it feel like a barracks rather than a palace, and why several of its museums are military.