The town is at a height of 1,690 meters above sea level. It is one of the oldest towns in the Mixteca region of Oaxaca, dating back to the 12th century AD. The first Spanish visitor was the Dominican friar Gonzalo Lucero, who passed through in the year 1536 on a journey of exploration. Three years lated the monk Benito Hernández persuaded the natives to move to a new location, founded on 13 September 1542. Between 1600 and 1633 the town was moved to its current location in the north of the valley, with the first streets laid out in the Spanish style. The town was periodically shaken by earthquakes during the colonial period, destroying churches and other major buildings. The town was connected to the outside world by a telegraph line in March 1883. A rural health center was established in April 1938, and in 1944 an airfield was opened.
The municipality covers an area of 583.05 square kilometres (225.12 sq mi). As of 2005, the municipality had a total population of 33,401 in 6,165 households. Of these, 20,648 people spoke an indigenous language.