The Song dynasty is divided into two distinct periods, Northern and Southern. During the Northern Song (Chinese: 北宋; 960–1127), the Song capital was in the northern city of Bianjing (now Kaifeng) and the dynasty controlled most of what is now Eastern China. The Southern Song (Chinese: 南宋; 1127–1279) refers to the period after the Song lost control of its northern half to the Jurchen Jin dynasty in the Jin–Song Wars. During this time, the Song court retreated south of the Yangtze and established its capital at Lin'an (now Hangzhou). Although the Song dynasty had lost control of the traditional "birthplace of Chinese civilization" along the Yellow River, the Song economy was still strong, as the Southern Song Empire contained a large population and productive agricultural land. The Southern Song dynasty considerably bolstered its naval strength to defend its waters and land borders and to conduct maritime missions abroad. To repel the Jin, and later the Mongols, the Song developed revolutionary new military technology augmented by the use of gunpowder. In 1234, the Jin dynasty was conquered by the Mongols, who took control of northern China, maintaining uneasy relations with the Southern Song. Möngke Khan, the fourth Great Khan of the Mongol Empire, died in 1259 while besieging the city of Chongqing. His younger brother Kublai Khan was proclaimed the new Great Khan, though his claim was only partially recognized by the Mongols in the west. In 1271, Kublai Khan was proclaimed the Emperor of China. After two decades of sporadic warfare, Kublai Khan's armies conquered the Song dynasty in 1279. The Mongol invasion led to a reunification under the Yuan dynasty (1271–1368).
The population of China doubled in size during the 10th and 11th centuries. This growth was made possible by expanded rice cultivation in central and southern Song, the use of early-ripening rice from south-east and southern Asia, and the production of widespread food surpluses. The Northern Song census recorded 20 million households, double of the Han and Tang dynasties. It is estimated that the Northern Song had a population of some 120 million people, and 200 million by the time of the Ming dynasty. This dramatic increase of population fomented an economic revolution in pre-modern China. The expansion of the population, growth of cities, and the emergence of a national economy led to the gradual withdrawal of the central government from direct involvement in economic affairs. The lower gentry assumed a larger role in grassroots administration and local affairs. Appointed officials in county and provincial centers relied upon the scholarly gentry for their services, sponsorship, and local supervision.
Social life during the Song was vibrant. Citizens gathered to view and trade precious artworks, the populace intermingled at public festivals and private clubs, and cities had lively entertainment quarters. The spread of literature and knowledge was enhanced by the rapid expansion of woodblock printing and the 11th-century invention of movable-type printing. Technology, science, philosophy, mathematics, and engineering flourished over the course of the Song. Philosophers such as Cheng Yi and Zhu Xi reinvigorated Confucianism with new commentary, infused with Buddhist ideals, and emphasized a new organization of classic texts that brought out the core doctrine of Neo-Confucianism. Although the institution of the civil service examinations had existed since the Sui dynasty, it became much more prominent in the Song period. The officials who gained power by succeeding in the exams became a leading factor in the shift from a military-aristocratic elite to a bureaucratic elite.
After usurping the throne of the Later Zhou dynasty, Emperor Taizu of Song (r. 960–976) spent sixteen years conquering the rest of China, reuniting much of the territory that had once belonged to the Han and Tang empires and ending the upheaval of the Five Dynasties and Ten Kingdoms period. In Kaifeng, he established a strong central government over the empire. The establishment of this capital marked the start of the Northern Song period. He ensured administrative stability by promoting the civil service examination system of drafting state bureaucrats by skill and merit (instead of aristocratic or military position) and promoted projects that ensured efficiency in communication throughout the empire. In one such project, cartographers created detailed maps of each province and city that were then collected in a large atlas. Emperor Taizu also promoted groundbreaking scientific and technological innovations by supporting such works as the astronomical clock tower designed and built by the engineer Zhang Sixun.
The Song court maintained diplomatic relations with Chola India, the Fatimid Caliphate of Egypt, Srivijaya, the Kara-Khanid Khanate of Central Asia, the Goryeo kingdom in Korea, and other countries that were also trade partners with Japan. Chinese records even mention an embassy from the ruler of "Fu lin" (拂菻, i.e. the Byzantine Empire), Michael VII Doukas, and its arrival in 1081. However, China's closest neighbouring states had the greatest impact on its domestic and foreign policy. From its inception under Taizu, the Song dynasty alternated between warfare and diplomacy with the ethnic Khitans of the Liao dynasty in the northeast and with the Tanguts of the Western Xia in the northwest. The Song dynasty used military force in an attempt to quell the Liao dynasty and to recapture the Sixteen Prefectures, a territory under Khitan control since 938 that was traditionally considered to be part of China proper (Most parts of today's Beijing and Tianjin). Song forces were repulsed by the Liao forces, who engaged in aggressive yearly campaigns into Northern Song territory until 1005, when the signing of the Shanyuan Treaty ended these northern border clashes. The Song were forced to provide tribute to the Khitans, although this did little damage to the Song economy since the Khitans were economically dependent upon importing massive amounts of goods from the Song. More significantly, the Song state recognized the Liao state as its diplomatic equal.