There has probably always been a village of some sort on the site where Chiang Mai stands today. The location is a natural spot for people to settle down. The "New City," which is what Chiang Mai means, as we see it today was founded by King Mengrai in 1292, making it 710 years old in 2002. The story goes that Mengrai founded Chiang Mai and moved the capital of Lanna there from Chiang Rai after conquering the Haripunchai around what is now Lamphun. Within the roughly square city walls, Mengrai founded the temple of Wat Chiang Man, while outside the city he built many small forts such as Wiang Kum Kam to consolidate his hold on the kingdom.
Mengrai ruled for 21 years and founded a dynasty that ruled the north for 200 years. The kingdom of Lanna reached its height in the late fifteenth century under King Tilokaracha, who commissioned a special temple (Wat Jed Yod) for the Eighth Buddhist Conference celebrating Buddhism's 2000th anniversary, which he convened there in 1477.
During one of the many wars between the Kingdoms of Siam and Burma, Chiang Mai fell under Burmese rule in the late sixteenth century, and remained under their rule for 200 years. When King Taksin finally expelled the Burmese in the late eighteenth century, he claimed Chiang Mai, which became a tributary of the kingdom of Siam. Chiang Mai remained a separate state until the death of the last Prince of Chiang Mai in 1939, at which time it came under the central administration of Bangkok.