The gatehouse providing entry from the outer defences to the castle proper was erected by King James IV, and was probably completed around 1506. It originally formed part of a Forework, extending as a curtain wall across the whole width of Castle Hill. At the centre is the gatehouse itself, which now stands to less than half its original height. The round towers at the outer corners rose to conical roofs, with battlements carried around the tops of the towers.
These were flanked by more round towers, of which only traces now remain, and mirrored by further rounds at the rear of the gatehouse. The overall design, as drawn by John Slezer in 1693, shows French influence, and has parallels with the forework erected at Linlithgow Palace.
Like the Linlithgow structure, the Forework was probably intended more for show, evoking the "age of chivalry", than for defence, as it would have offered little protection against contemporary artillery. The entrance was via a central passage, flanked by two separate pedestrian passages. This triple arrangement was unusual in its time, and Classical triumphal arches have been suggested as an influence. The gatehouse was dismantled gradually, and was consolidated in its present form in 1810. At each end of the crenellated curtain wall was a rectangular tower.
The west tower, known as the Prince's Tower, probably after Henry, Prince of Scotland, survives to its full height, and is now attached to the later palace. At the east end, the Elphinstone Tower contained a kitchen and possibly an officer's lodging. It was cut down to form a gun battery, probably in the early 18th century when the Outer Defences were rebuilt.