Thousands of years ago, the area where Taipei now stands was a lake. Over centuries, the lake dried up, becoming a dry basin punctuated with swamps and grassy lowlands. The people of the Pingpu tribe - probably descended from Pacific Islanders - lived in elevated areas surrounding the basin and fished the waterways in canoes. A few hundred years ago, a group of Han Chinese settled in the area. They also used the waterways to fish, keeping to the banks of the Tamsui River some distance from modern Taipei.
In 1790, a farmer from Fukien Province on the mainland established a farm at Takala in what is now central Taipei. This was the beginning of a large-scale migration to the area, and led to the formation of several settlements. The most concentrated area of settlement - the earliest in the Taipei area - was known as Manka. Other locations including Talungtung, Sungshan and Shihlin also became populated by Chinese mainland communities. Control of the emerging city of Taipei was divided among immigrants from different areas of mainland China. This broad power-sharing led to frequent armed clashes. After a large battle in 1853, settlers from Chuanchou fled north to Tataocheng on the banks of the Tamsui River. Their farming efforts eventually led to a new and prosperous community which dominated Manka by the late 19th century. The Tamsui River brought commerce and prosperity, with trade in tea and camphor taking place along the waterfront. Both Manka and Tataocheng sprang up because of their proximity to the Tamsui River, not only the vital force behind the development of early Taipei, but also a major artery in the city's subsequent development.
In 1875, the Prefecture of Taipei was established in what is now the Chungcheng District of the city. Taipei's early construction was based on traditional Chinese geomancy, with walls to the east and west, mountains surrounding and the Hsintien River as the required body of water in front. The city faced north-south with the four main walls penetrated by five city gates. The area within the walls was referred to as Cheng-nei ('inside the city walls'). The Ching Dynasty established administrative and financial agencies in the fledgling city and when the Japanese colonised Taiwan in 1895, they also set up administrative headquarters in Taipei and continued to develop the city. Under the management of its different rulers the area within the city walls evolved from wide open countryside into the administrative, economic and cultural centre of Taiwan in just 100 years.
Japanese rule was harsh, and led to widespread dissatisfaction among the Taiwanese. During this time, though, the Japanese built roads and infrastructure, developing Taiwan as it would any other Japanese city. With WWII came allied bombing and the destruction of much of this infrastructure, and by the end of the war, the economy of Taiwan was in ruins. Under the Yalta Agreement at the end of the war, Taiwan came under Chinese rule. Taiwanese happiness at getting rid of the Japanese didn't last long, with the corrupt General Chen Yi sent from China as governor. In 1947 anti-Chinese riots broke out and were brutally repressed: as many as 30,000 civilians were killed. Until the lifting of martial law in 1987, this incident - known as '2-28' - was a forbidden topic.
When the Communists took over China in 1949, the Chinese ruler Chiang Kai-shek moved his government to Taiwan: thus began the 'two Chinas' saga. The PRC (mainland China) became entangled in the Korean War, so the anticipated invasion of the ROC (Taiwan) never took place. The ROC government always claimed that their presence in Taipei was temporary, but that until they re-took the mainland, no political opposition was allowed. Although they weren't popular with many native Taiwanese, the ROC government was embarking on a successful rebuilding program. With rapid industrialisation in the 1960s, Taiwan became one of the wealthiest countries in Asia.
In 1971 the ROC lost the China United Nations seat to the mainland and in 1979 the US - and most other countries - withdrew recognition of the ROC government. Unofficially, however, most countries continued to support Taiwanese self governance. In 1986 political reform was given a much-needed boost with opposition parties taking seats in the Taiwanese legislature, and when martial law was lifted in 1987 things looked good. Moving into high-tech industries, the country quickly shed the old stigma attached to the 'Made in Taiwan' label, and managed to largely overcome the recent Asian economic crisis.
In 1994 the ROC began lobbying the UN for a seat. To the mainland, this was a clear declaration of independence. A few missiles crashing into the sea 25km (15mi) off the Taiwanese coast did nothing to dampen the island's resolve; they even invited the Dalai Lama for a six-day visit in 1997. Taipei was mildly affected by the 1999 earthquake that hit the centre of Taiwan.
Taipei continues to be the focus for tense communications with China regarding the 'One China' policy. Taiwan's president Chen Shui-bian's proposals for negotiations with Beijing to discuss reconciliation have had a cool reception. The Chinese Foreign Ministry's position is that Taiwan must accept it is a part of China before anything can be discussed.
Chen's re-election in March 2004 has many of Taipei's denizens fearing further strains in the relationship with China. In 2005, leaders of the KMT and PFP parties visited China and met with top officials including Hu Jintao to try to improve cross-strait relations. The Chinese government has said it is happy to meet with anyone who supports the one-china policy, which means of course that they still refuse to negotiate or talk with Chen Shui Bian. In 2006, Chen scrapped the National Unification Council. Many see this as a clear step toward formally declaring independence. Neither the US nor China were pleased with the move even though the council had been dormant for many years. Right now there is a push to impeach or recall the president but it is too early to see if this will succeed or have much impact on politics here in the long run.