Long before the Spanish Conquest, the Sabana de Bogotá, a fertile highland basin that today has been almost entirely taken over by the city, was inhabited by one of the most advanced pre-Columbian indigenous groups, the Muisca. The Spanish era began when Gonzalo Jiménez de Quesada and his expedition arrived at the Sabana, founding the town on August 6, 1538, near the Muisca capital, Bacatá.

The town was named Santa Fe de Bogotá, a combination of the traditional name, Bacatá, and Quesada's hometown in Spain, Santa Fe. Nonetheless, throughout the colonial period the town was simply referred to as Santa Fe.

At the time of its foundation Santa Fe consisted of 12 huts and a chapel, where a Mass was held to celebrate the town's birth. The Muisca religious sites were destroyed and replaced by churches.

During the early years Santa Fe was governed from Santo Domingo (on the island of Hispaniola, the present-day Dominican Republic), but in 1550 it fell under the rule of Lima, the capital of the Viceroyalty of Peru and the seat of Spain's power for the conquered territories of South America. In 1717 Santa Fe was made the capital of the Virreinato de la Nueva Granada, the newly created viceroyalty comprising the territories of present-day Colombia, Panama, Venezuela and Ecuador.

Despite the town's political importance, its development was hindered by the area's earthquakes, and also by the smallpox and typhoid epidemics that plagued the region throughout the 17th and 18th centuries.

After independence, the Congress of Cúcuta shortened the town's name to Bogotá in 1821 and decreed it the capital of Gran Colombia. The town developed steadily and by the middle of the 19th century it had 30,000 inhabitants and 30 churches. In 1884 the first tramway began to operate in the city and, soon after, railway lines were constructed to La Dorada and Girardot, giving Bogotá access to the ports on the Río Magdalena.

Rapid progress came only in the 1940s with industrialization and the consequent peasant migrations from the countryside. On April 9, 1948, the popular leader Jorge Eliécer Gaitán was assassinated, sparking the uprising known as El Bogotazo. The city was partly destroyed; 136 buildings were burnt to the ground and 2500 people died.

Tranquil life in Bogotá was rocked again on November 6, 1985, when guerrillas of the M-19 (Movimiento 19 de Abril) revolutionary movement invaded the Palace of Justice in Bogotá and made hostages of the 300-plus civilians in the building. By the next day, 115 people were dead, including 11 Supreme Court judges.

Colombia's historic 2016 peace deal with Revolutionary Armed Forces of Colombia (FARC), which ended a 52-year civil war, has Bogotá breathing a long-awaited sigh of relief. Dramatically improved safety, along with a host of progressive projects under successive mayors (eg the 350km of CicloRuta bike lanes), have helped the city make major strides toward positioning itself as not only a cultural capital but a destination in its own right.