Throughout the dynasties, the emperor has the supreme power and status, as the king of a country, the emperor's safety is the most important thing for a country.
So, in ancient times, how to put the emperor's safety into practice?
For thousands of years, each dynasty had its own unique approach, and in general, later dynasties paid more attention to the safety and security of the emperor than the previous dynasties, especially the Song dynasty and the Ming Dynasty.

Song Dynasty: Unprecedented in history, the largest guard army ——— the "Three Forbidden Army" established by Zhao Kuangyin, the Song Dynasty's large-scale forbidden army, and the strict and meticulous security system, which is unprecedented.
Zhao Kuangyin, the grandfather of the Song Dynasty, who once served as the general of the Forbidden Army in front of the Palace in the Later Zhou Dynasty, relied on soldiers to become the king of a country and sat on the whole world, so he was well aware of the role of the guard. As the founding emperor of the Song Dynasty, Zhao Kuangyin attached great importance to the formation of the Forbidden Army, in order to build a strong national guard. Zhao Kuangyin not only made every effort to build a elite janissary in the central authorities, but also strengthened the integration of the army at the local level, so that the scale of the central forbidden army was expanded unprecedentedly.
During the Kaibao period of Song Taizu, the number of soldiers in the Song Dynasty reached 378,000, and the forbidden army accounted for 194,000, up to 51 percent. Later, other rulers of the Song Dynasty also attached great importance to the construction of the forbidden army, resulting in a further expansion of the number of forbidden troops. By the time of Emperor Taizong of Song, of the 660,000 soldiers in the country, the forbidden army accounted for 54 percent. By the time of Emperor Renzong of Song' reign, the number of forbidden troops was as high as 826,000.
However, it should be noted that the forbidden army of the Song Dynasty not only protected the monarch, but also defended the country. When necessary, the forbidden army had to go out on behalf of the country, so only a small part of the forbidden army was stationed in the local area, and most of the forbidden army was stationed outside the capital city to defend the capital. As the forbidden army of the Song Dynasty, training was their daily essential work, such as: Lin Chong, the hero of Shi Nai'an's pen, as the godhead of hundreds of thousands of forbidden troops, he had superb gun and stick kung fu.
The Song Dynasty's "Three Forbidden Armies" were subordinate to the national guard system, and were divided into several parts, such as "Dianqian Division", "Imperial City Division", "Bodyguard Division", and "Imperial Front Zhongzuo Military Head Division", and within each division, there were a number of detailed units, responsible for different security priorities, each performing its own duties. From the huge system of forbidden troops, after careful selection at all levels, excellent forbidden troops were selected to serve as personal guards of the emperor and the imperial palace, and these forbidden troops were divided into two categories: "squad" and "straight", taking turns to take up posts and perform their duties.
However, the forbidden army of the Song Dynasty had obvious ritualization and was mostly useless decoration. Due to the large number of forbidden troops, when the national strength of the Song Dynasty declined, the salaries of the forbidden army were a big problem. Even Song Shenzong sighed: "Poor people of our country, redundant soldiers." After that, in order to eliminate redundant troops, the imperial court would reorganize the forbidden army once a year.
In the Southern Song Dynasty, the scale of the forbidden army was greatly reduced.
Ming Dynasty: The most in-place "secret police" system in history ——— the "Shang twelve guards" security system created by Zhu Yuanzhang, these non-commissioned officers are selected through rigorous training and selected soldiers with strong physique and extraordinary martial arts. Founded by Zhu Yuanzhang, the founding emperor of the Ming Dynasty, in the fifteenth year of Hongwu (1382 AD).
The Ming Dynasty required more stringent requirements for the security of the monarch. The introduction of the secret police detective, the "secret police" system in the modern security system, is the most prominent point of this. As the founding emperor of the Ming Dynasty, Zhu Yuanzhang, when he was not called emperor, created the "Gongwei Division of the Guards on the Straight Army" as his direct subordinate guard unit. After Zhu Yuanzhang became emperor, it was expanded the following year and renamed "Pro-Military Governor's Mansion".
Wei and Wei were military units of the Ming Dynasty, of which the "Wei Commander" was the person in charge of Wei. In the fifteenth year of Hongwu, Zhu Yuanzhang abolished the "Yiluan Division" and the "Pro-Military Governor's Office" as the former Royal Guard, and based on the National Guard and the Institute, created the "JinyiWei Pro-Army Command and Envoy Division", a powerful Royal Guard Regiment, which is the famous "JinyiWei" in history.
In the fifteenth year of Hongwu, a series of Janissaries such as the "Fuqian Military Guard" and the "Flag Bearer Guard" were created by the founding emperor, and there were twelve of them, called the "Twelve Guards of the Upper Twelve". The emperor directly controlled the command of the Twelve Guards, and the Ming Dynasty's Ministry of Defense "Five Armies Governor's Office" had no right to lead. Undoubtedly, the Jinyi Wei Commandery was the most powerful of the "Twelve Guards" system, but the "direct driving of the guards, patrolling and arresting" had greater power and scale, which was not much different from the "embroidered clothes direct command envoy" in the period of Emperor Liu Che of the Han Dynasty.
After Ming Chengzu Zhu Di usurped the throne, because he was very fond of this security system, he restored the "Jinyi Wei Zhen Fusi", which had been revoked by Zhu Yuanzhang. At the same time, on the basis of the Twelve Guards, the Twenty-second Guards were formed, creating a set of "police and army" combination, a more advanced monarchy defense system than the Han and Tang Dynasties. As a military stronghold in Kyoto, the "police" is the Five Cities Terracotta Division, who is responsible for patrolling and maintaining security in the capital area.
In addition, the sensational organization of the "East Factory" was the product of the Ming Emperor Zhu Yuanzhang's efforts to strengthen the absolute monarchy, and the eunuchs who were particularly favored by the emperor served as the factory owners, but in fact they directly obeyed the emperor. The "West Factory" was established during the reign of Emperor Mingxianzong, and complemented the "East Factory" as a secret police agency. This institution, notorious in history, exacerbated the political corruption of the Ming Dynasty and made it even more "short-lived".
The East Factory, the West Factory, the Jinyi Guards and the Normal Guard Force are the four pillars of the National Leaders Protection Network, which have converged into a powerful force to protect the country's leaders and exert unprecedented control over society. Later, after the establishment of the Qing Dynasty, it followed the example of the Ming Dynasty and inherited this security system. At the same time, the rulers of the Qing Dynasty not only paid attention to their origins when selecting guards, but also had very strict rules:
It must be the son of a Manchu official eunuch, and directly responsible for the emperor's guard, the attendant and guard of the gate, which is a major feature of the Manchu Qing with "racial color".
Moreover, in order to ensure the personal safety of the emperor, the personal guard was served by the "Shangsanqi Bodyguard", who had to be selected from the Shangsanqi. This security system was also used by the Manchu emperors until the fall of the Qing Dynasty.
Resources:
["Song Shi Taizu Benji", "Song Shi Bing Zhi", "Ming Shi Cheng zu III", "Manchu Old File"]