There is no certainty as to when humans first occupied the area prior to the first visits of Europeans in the 15th century. The earliest known remnants in the region were found at Peers cave in Fish Hoek and date to around 12,000 years ago.
Little is known of the history of the region's first residents, since there is no written history from the area before it was first mentioned by Portuguese explorer Bartolomeu Dias in 1486. Vasco da Gama recorded a sighting of the Cape of Good Hope in 1497, and the area did not have regular contact with Europeans until 1652, when the Netherlands' Jan van Riebeeck and other employees of the Dutch East India Company (Dutch: Verenigde Oost-indische Compagnie, VOC) were sent to the Cape to establish a way-station for ships travelling to the Dutch East Indies, and the Redout Duijnhoop (later replaced by the Castle of Good Hope). The city grew slowly during this period, as it was hard to find adequate labour. This labour shortage prompted the city to import slaves from Indonesia and Madagascar. Many of these became ancestors of the first Cape Coloured communities.
During the French Revolutionary and Napoleonic wars, the Netherlands was repeatedly occupied by France, and Great Britain moved to take control of Dutch colonies. Britain captured Cape Town in 1795, but the Cape was returned to the Netherlands by treaty in 1803. British forces occupied the Cape again in 1806 following the Battle of Bloubergstrand. In the Anglo-Dutch Treaty of 1814, Cape Town was permanently ceded to Britain. It became the capital of the newly formed Cape Colony, whose territory expanded very substantially through the 1800s.
The discovery of diamonds in Griqualand West in 1869, and the Witwatersrand Gold Rush in 1886, prompted a flood of immigrants to South Africa. Conflicts between the Boer republics in the interior and the British colonial government resulted in the Second Boer War of 1899-1901, which Britain won. In 1910, Britain established the Union of South Africa, which unified the Cape Colony with the two defeated Boer Republics and the British colony of Natal. Cape Town became the legislative capital of the Union, and later of the Republic of South Africa.
In the 1948 national elections, the National Party won on a platform of apartheid (racial segregation) under the slogan of "swart gevaar". This led to the Group Areas Act, which classified all areas according to race. Formerly multi-racial suburbs of Cape Town were either purged of unlawful residents or demolished. The most infamous example of this in Cape Town was District Six. After it was declared a whites-only region in 1965, all housing there was demolished and over 60,000 residents were forcibly removed. Many of these residents were relocated to the Cape Flats and Lavender Hill. Under apartheid, the Cape was considered a "Coloured labour preference area", to the exclusion of "Bantus", i.e. blacks.
Cape Town was home to many leaders of the anti-apartheid movement. On Robben Island, a former penitentiary island 10 kilometres from the city, many famous political prisoners were held for years. In one of the most famous moments marking the end of apartheid, Nelson Mandela made his first public speech in decades on 11 February 1990 from the balcony of Cape Town City Hall hours after being released. His speech heralded the beginning of a new era for the country, and the first democratic election was held four years later, on 27 April 1994. Nobel Square in the Victoria & Alfred Waterfront features statues of South Africa's four Nobel Peace Prize winners - Albert Luthuli, Desmond Tutu, F.W. de Klerk and Nelson Mandela. Since 1994, the city has struggled with problems such as HIV/AIDS, tuberculosis, a surge in violent drug-related crime and more recent xenophobic violence. At the same time, the economy has surged to unprecedented levels due to the boom in the tourism and the real estate industries.
The Blaauwberg area of Cape Town also has a fascinating history.
The Battle of Blaauwberg was also a pivotal point in the history of cape Town, South Africa and indeed the world.
Historical photos of Cape Town also paint a fascinating picture of the development of this city over the years.
See also http://en.wikipedia.org/wiki/History_of_Cape_Town