Nanjing was one of the earliest established cities in the southern China area. According to the legend, Fu Chai, the Lord of the State of Wu, founded the first city, Yecheng (冶城) in today's Nanjing area in 495 BC. Later in 473 BC, The State of Yue conquered Wu and constructed the city of Yuecheng (越城) on the outskirts of the present-day Zhonghua Gate. In 333 BC, after eliminating the State of Yue, the State of Chu built Jinling Yi (金陵邑) in the northwestern part of present-day Nanjing. Since then, the city has experienced numerous destructions and reconstructions.

The City Wall of Nanjing, the world's longest, built in the Ming Dynasty (1368-1644)
Nanjing first became a capital in AD 229, where Sun Quan of the Wu Kingdom during the Three Kingdoms Period relocated its capital to Jianye (建鄴), a city he extended on the basis of Jinling Yi in AD 211. After the invasion of the Five Hu, the nobles and wealthy families of the Jin Dynasty escaped across the Yangtze River and established Nanjing as the capital, which was then called Jiankang (建康). Thereafter, Jiankang remained as the capital of Southern China during the North-South Division period, until Sui Dynasty reunified China and destroyed almost the entire city, turning it into a small town.

The city was reconstructed during the late Tang Dynasty. It was again named capital (then known as Jinling (金陵)) during the short-lived Southern Tang Kingdom (937 – 975) (who renamed it Xidu), who succeeded the Wu Kingdom. Jiankang's textile industry burgeoned and thrived during Song Dynasty despite the constant threat from the northern foreign invasions. The Mongolians, the occupiers of China, further consolidated the city's status as a hub of the textile industry under the Yuan Dynasty.

Divine Trail, located in Eastern Suburb Scenic Area of Nanjing, was built in the Ming Dynasty
The first emperor of the Ming Dynasty Zhu Yuanzhang (朱元璋)who overthrew the Yuan Dynasty rebuilt this city and made it the capital of China in 1368. He constructed what was the longest city wall in the world at that time. It took 200,000 laborers 21 years to finish the project. The present-day city wall of Nanjing was mainly built during that time, and it is the longest surviving city wall in the world.

Jiming Buddhist Temple
It is believed that Nanjing was the largest city in the world from 1358 to 1425 with a population of 487,000 in 1400.
During the Qing Dynasty (1644-1911), the Nanjing area was known as Jiangning (江宁) and served as the seat of government for the Liangjiang Viceroy. Nanjing was the capital of the Taiping Kingdom in the mid-19th century, being renamed as Tianjing (天京) (lit. Heaven's Capital). Both the Viceroy and the Taiping king resided in buildings that would later be known as the Presidential Palace. As Qing general Zeng Guofan(曾国藩) retook the city in 1864, massive slaughtering occurred in the city with over 100,000 committing suicide or fighting to the death.
