Mēxihco is the Nahuatl term for the heartland of the Aztec Empire, namely, the Valley of Mexico, and its people, the Mexica, and surrounding territories. This became the future State of Mexico as a division of New Spain prior to independence (compare Latium). It is generally considered to be a toponym for the valley which became the primary ethnonym for the Aztec Triple Alliance as a result, or vice versa. After New Spain won independence from Spain, representatives decided to name the new country after its capital, Mexico City. This was founded in 1524 on top of the ancient Mexica capital of Mexico-Tenochtitlan.
Traditionally, the name Tenochtitlan was thought to come from Nahuatl tetl [ˈtetɬ] ("rock") and nōchtli [ˈnoːtʃtɬi] ("prickly pear") and is often thought to mean "Among the prickly pears [growing among] rocks". However, one attestation in the late 16th-century manuscript known as "the Bancroft dialogues" suggests the second vowel was short, so that the true etymology remains uncertain.
The suffix -co is the Nahuatl locative, making the word a place name. Beyond that, the etymology is uncertain. It has been suggested that it is derived from Mextli or Mēxihtli, a secret name for the god of war and patron of the Mexica, Huitzilopochtli, in which case Mēxihco means "place where Huitzilopochtli lives". Another hypothesis suggests that Mēxihco derives from a portmanteau of the Nahuatl words for "moon" (Mētztli) and navel (xīctli). This meaning ("place at the center of the moon") might refer to Tenochtitlan's position in the middle of Lake Texcoco. The system of interconnected lakes, of which Texcoco formed the center, had the form of a rabbit, which the Mesoamericans pareidolically associated with the moon rabbit. Still another hypothesis suggests that the word is derived from Mēctli, the name of the goddess of maguey.
The name of the city-state was transliterated to Spanish as México with the phonetic value of the letter 'x' in Medieval Spanish, which represented the voiceless postalveolar fricative [ʃ]. This sound, as well as the voiced postalveolar fricative [ʒ], represented by a 'j', evolved into a voiceless velar fricative [x] during the 16th century. This led to the use of the variant Méjico in many publications in Spanish, most notably in Spain, whereas in Mexico and most other Spanish–speaking countries México was the preferred spelling. In recent years the Real Academia Española, which regulates the Spanish language, determined that both variants are acceptable in Spanish but that the normative recommended spelling is México. The majority of publications in all Spanish-speaking countries now adhere to the new norm, even though the alternative variant is still occasionally used. In English, the 'x' in Mexico represents neither the original nor the current sound, but the consonant cluster [ks].
The official name of the country has changed as the form of government has changed. The declaration of independence signed on November 6, 1813 by the deputies of the Congress of Anáhuac called the territory América Septentrional (Northern America). On two occasions (1821–1823 and 1863–1867), the country was known as Imperio Mexicano (Mexican Empire). All three federal constitutions (1824, 1857 and 1917, the current constitution) used the name Estados Unidos Mexicanos—or the variant Estados-Unidos Mexicanos, all of which have been translated as "United Mexican States". The phrase República Mexicana, "Mexican Republic", was used in the 1836 Constitutional Laws.