The history of Kathmandu is really a history of the Newar people, the main inhabitants of the Kathmandu Valley. While the documented history of the valley goes back to the Kiratis, around the 7th century BC, the foundation of Kathmandu itself dates from the 12th century AD, during the time of the Malla dynasty.
The original settlements, in what is the southern half of the old town, grew up around the trade route to Tibet and in early pilgrim resthouses such as the Kasthamandap, which later lent its name to the city.
Originally known as Kantipur, the city flourished during the Malla era, and the bulk of its superb temples, buildings and other monuments date from this time. Initially, Kathmandu was an independent city within the valley, but in the 14th century the valley was united under the rule of the Malla king of Bhaktapur. The 15th century saw division once more, this time into the three independent kingdoms of Kathmandu, Patan and Bhaktapur. Rivalry between the three city-states led to a series of wars that left each state weakened and vulnerable to the 1768 invasion of the valley by Prithvi Narayan Shah.
The ensuing Shah dynasty unified Nepal and made the expanded city of Kathmandu its new capital - a position the city has held ever since.