The short answer
Machu Picchu was built by the Incas, not the Aztecs. It sits in the Andes of southern Peru, high above the Urubamba River valley. The Aztec empire was centered in central Mexico, thousands of miles to the north, and the Spanish conquered its capital, Tenochtitlan, in 1521. The two are often mixed up because both were large empires that ended with the Spanish conquest, but Machu Picchu has no known Aztec connection.
When it was built
Most sources date the construction of Machu Picchu to the mid-1400s, around 1450. They credit Pachacuti, the ruler who expanded the Inca state from Cusco, and his successor. Some recent research argues for an earlier start, so treat the exact year as approximate.
What it was for
Most scholars think Machu Picchu was a royal estate or retreat rather than a town or a fortress. Its palaces, temples and carefully built terraces suggest use by the ruler and high-ranking people. The site also had fountains and water channels, which show how much planning went into it.
Why people confuse it with Aztec sites
Both the Aztec and Inca states were large American empires, and both were brought down after Spanish conquest. Their stories are often taught side by side, which makes it easy to assume that a famous ruin from one of them must belong to the other. Machu Picchu belongs to the Inca world, though, and the Aztec empire never reached the Andes.
Abandonment and rediscovery
Machu Picchu was abandoned around the time of the Spanish conquest, and the reason is not known. Some accounts suggest that a shortage of water may have played a part.
The site was not unknown to local people. In 1911, the Yale historian Hiram Bingham reached it with the help of Melchor Arteaga, a local Quechua speaker, and his expedition brought the site to wide international attention. Local families had known about the ruins for a long time before that.
Where it fits
Machu Picchu is best read as one royal site within the longer story of the Inca state. For the wider sequence of Inca dates, from the early rulers to the 1572 end of the last independent state, see the ancient Inca timeline.