The Mexican–American War took place between 1846 and 1848 between  United States  and Mexico.

Causes

When Mexico got independence from Spain in 1821, Texas was part of Mexico. Americans and other settlers came into Texas when Mexico allowed non-Spanish settlers to settle there.

After many settlers came to Texas, disputes led to the Texas Revolution in 1836, when Texas became independent. Mexico refused to recognize the Republic of Texas, as an independent country. Texas soon asked to join the United States.

The United States moved quickly to annex Texas after the 1844 election of James K. Polk. In his campaign, Polk had called for the "re-annexation" of Texas and the "re-occupation" of the Oregon Territory. Polk also wanted California and the rest of what is now the Southwestern United States.

In 1845, the United States annexed Texas. However, Mexico still did not recognize its independence or recognize the annexation. The US offered to buy from Mexico the land extending from Texas to the Pacific Ocean, but Mexico wanted to keep the vast area.

In 1846, a dispute over the border between Texas and Mexico resulted in armed conflict, and the Mexican–American War began. After offering to buy the territory, Polk moved US troops into a place that Mexico said was not in Texas but in the Mexican state of Coahuila.  The Mexican army attacked them.

The main cause of the war was the westward expansion of the United States. In the 19th century Americans believed it was their right to expand westward. They believed they could take over the people already living on the land and have it for the United States. Southerners wanted to have more slave states.

Antonio López de Santa Anna became president again. Many Mexicans hated him and did not want to follow him into war. Many Americans, including the young Abraham Lincoln, also disliked the war since they thought that it was to expand slavery.

War
In addition to small units sent to California and New Mexico, the US sent two major armies into Mexico under the commands of General Winfield Scott and future US President General Zachary Taylor.

After the US had entered Mexico, Mexican General Antonio López de Santa Anna took command of the Mexican soldiers in early 1847.  The US forces fought Santa Anna near Monterrey and Buena Vista. After Buena Vista, the Mexican army had many problems, including starvation, disease, and desertion. The Mexican government was unstable.

In March 1847, Scott landed at Veracruz. His force included future Civil War Generals Robert E. Lee, Ulysses S. Grant, Stonewall Jackson and George G. Meade as well as Commodore Perry. Scott took Puebla in May and took Mexico City in September after the Battle of Chapultepec.

When American soldiers came to California, the Bear Flag Revolt was happening. Some Californians were trying to leave Mexico and to form their own country, as had happened in Texas. In July and August 1846, American soldiers captured Monterey, Yerba Buena, and Los Angeles.  After a counterattack by the Californios, the Americans had taken much of California by 1847. The Mexican governor of California, Pio Pico, left the state.

Aftermath
The US won the war, and Mexico signed the Treaty of Guadalupe Hidalgo in 1848, which gave the US the area that would become the states of Arizona, California, New Mexico, Nevada, Utah, southwestern Colorado, and southwestern Wyoming. Mexico received 15 million US dollars and gave up its claims to Texas.

The slavery debate in the United States became more intense with the addition of the new territory and the question of whether slavery would be legal in the new territories. Also, many of the officers who would lead troops in the American Civil War fought in the Mexican-American War would use their experiences.

Nevada and California became part of the US with the signing of the Treaty of Guadalupe Hidalgo. Before then, Nevada was part of Alta California, which is now California, Baja California, Utah, about a quarter of Colorado, parts of Arizona, Wyoming and New Mexico.

The Act of Congress establishing California as the 31st state was part of the Compromise of 1850.

References

Other websites 
Library of Congress Guide to the Mexican War
The Handbook of Texas Online: Mexican War
Manifest Destiny and the U.S.-Mexican War: Then and Now
The Mexican War
 Mexican-American War Citizendium

1840s in the United States
1840s in Mexico
Wars involving the United States