Edinburgh was an important city politically, commercially and militarily. From 1437 it was Scotland's capital. As a Royal Burgh it had a regional monopoly on foreign trade. It would be the first city an invading army would reach after emerging from the Borders. So where are its walls?
Actually, Edinburgh had three walls that we know of. These are known as the King's Wall (pre-1427), the Flodden Wall (1513) and the Telfer Wall (1628). In all likelihood there may have been older walls, possibly palisades or earthworks, but no explicit mention of these has been preserved. However, there are mentions of gates going back to 1180, providing indirect evidence of their existence. These walls would have served a nominal defensive purpose, but mostly functioned as means to levy tolls on trade and traffic, and as a barrier against smugglers. Nevertheless, the King's Wall was a military structure, leading King James II to issue a charter in 1450 for its strengthening, because the people of Edinburgh "dread the evil and injury of our enemies of England."
As you can see on the map, the King's Wall (in orange) only enclosed a tiny part of the city, with the Cowgate well outside. A comparison to the Flodden Wall (in red) of not even 100 years later is a testament to the city's rapid expansion in the late medieval period. At that point Edinburgh was one of only three cities in Scotland to have stone walls, the others being Perth and Stirling. Hardly anything remains of the King's Wall, which may be explained by its positioning halfway down the slope between the Mile and the Cowgate, and perpendicular to the direction of the closes. The only section of masonry nowadays thought to have been part of the King's Wall can be found in Tweeddale Court. It must be said, though, that a recent excavation near the Cowgate unearthed a section of medieval wall, leading to speculation whether this may be part of the King's Wall, which would then have been situated significantly lower on the slope than has heretofore been assumed.
The next great wall-building project was started in 1513, just after the disastrous Battle of Flodden. A Scottish army led by King James IV was crushed by the English, granting James the dubious honour of being the last British monarch to fall in battle. When news of the defeat reached Edinburgh, the burgesses of the town decided to waste no time and started to extend their defenses. The Flodden Wall, as it came to be known, extended south from the Castle, skirted the Vennel, enclosed Greyfriars, then running roughly parallel to the Royal Mile until reaching the Pleasance. There it made a sharp turn back to the Mile, incorporacting the Netherbow Port, then running down towards the valley of the Nor'Loch. The Loch formed a natural barrier in the north, so there was no need for additional protection there.
The new wall encompassed a significantly larger area than the King's Wall had, yet that area was still only about 1/4 sq. mile. Until the middle of the 18th century, this was the outline of the Royal Burgh and in order to enjoy the privileges that came with it, one had to live within those walls. It's hard to find reliable census information about this period, but most figures for Edinburgh's population fall between 8,000 and 12,000 for the period in which the Flodden Wall was constructed. After a hundred years, it had grown to 20,000-25,000; a mere twenty years later, it reached 30,000; and when in 1755 an official census was taken, the population had risen to 57,000!
The 1628 Telfer Wall (purple on the map) didn't bring much relief, expanding the city from 140 to 150 acres, so by the mid-1700's the city was bursting at the seams. But it was around this time that the ancient privileges of the Royal Burgh were revoked, which meant that there was no longer any need for medieval-style walls. Within 30 years' time, most of the bastions had been dismantled and the gates destroyed. Whenever a section of wall got in the way of expansion, it was knocked down, and some bits were so badly neglected that they fell down spontaneously. Nowadays very little remains, but if you know where to look you can still find small sections here and there.