Samurai is the term for the military nobility of pre-industrial Japan. According to translator William Scott Wilson: "In Chinese, the character "侍" was originally a verb meaning to wait upon or accompany a person in the upper ranks of society, and this is also true of the original term in Japanese, saburau. In both countries the terms were nominalized to mean "those who serve in close attendance to the nobility," the pronunciation in Japanese changing to saburai. According to Wilson, an early reference to the word "samurai" appears in the Kokin Wakashū (905–914), the first imperial anthology of poems, completed in the first part of the 10th century.
By the end of the 12th century, samurai became almost entirely synonymous with bushi, and the word was closely associated with the middle and upper echelons of the warrior class. The samurai followed a set of rules that came to be known as Bushidō. While they numbered less than 10% of Japan's population samurai teachings can still be found today in both everyday life and in martial arts such as Kendō, meaning the way of the sword.
Following the Battle of Hakusukinoe against Tang China and Silla in 663 AD that led to a Japanese retreat from Korean affairs, Japan underwent widespread reform. One of the most important was that of the Taika Reform, issued by Prince Naka no Ōe (Emperor Tenji) in 646 AD. This edict allowed the Japanese aristocracy to adopt the Tang Dynasty political structure, bureaucracy, culture, religion, and philosophy. As part of the Taihō Code, of 702 AD, and the later Yōrō Code, the population was required to report regularly for census, which was used as a precursor for national conscription. The Taihō Code classified most of the Imperial bureaucrats into 12 ranks, each divided into two sub-ranks, 1st rank being the highest adviser to the Emperor. Those of 6th rank and below were referred to as "samurai" and dealt with day-to-day affairs. Although these "samurai" were civilian public servants, the name is believed to have derived from this term. Military men, however, would not be referred to as "samurai" for many more centuries.
Ultimately, Emperor Kammu disbanded his army. From this time, the Emperor's power gradually declined. While the Emperor was still the ruler, powerful clans around Kyoto assumed positions as ministers, and to amass wealth these magistrates often imposed heavy taxes, resulting in many farmers becoming landless.
Some clans were originally formed by farmers who had taken up arms to protect themselves from the Imperial magistrates sent to govern their lands and collect taxes. These clans formed alliances to protect themselves against more powerful clans, and by the mid-Heian period they had adopted characteristic Japanese armor and weapons, and laid the foundations of Bushido, their ethical code.
After the Genpei war of the late 12th century, a clan leader Minamoto no Yoritomo was allowed to organize soldiers and police. Though the initial responsibility was restricted to arresting rebels and collecting needed army provisions, and forbidden to interfere Kokushi Governors, the responsibility expanded gradually and thus samurai-class appeared as political ruling power in Japan. Minamoto no Yoritomo opened Kamakura Bakufu Shogunate in 1192.
Samurai warriors described themselves as followers of "The Way of the Warrior" or Bushido. Bushidō is defined by the Japanese dictionary Shogakukan Kokugo Daijiten as "a unique philosophy that spread through the warrior class from the Muromachi period. From the earliest times, the Samurai felt that the path of the warrior was one of honor, emphasizing duty to one's master, and loyalty unto death."
By the 12th century, upper-class samurai were highly literate due to the general introduction of Confucianism from China during the 7th to 9th centuries, and in response to their perceived need to deal with the Imperial Court, who had a monopoly on culture and literacy for most of the Heian Period. As a result they aspired to the more cultured abilities of the nobility.
Japanese war tactics and technologies improved rapidly in the 15th and 16th century. Use of large numbers of infantry called ashigaru ("light-foot," due to their light armor), formed of humble warriors or ordinary people with a long lance was introduced and combined with cavalry in maneuvers. The number of people mobilized in warfare ranged from thousands to hundreds of thousands.
The arquebus, a matchlock gun, was introduced by the Portuguese via a Chinese pirate ship in 1543 and the Japanese succeeded in assimilating it within a decade. Groups of mercenaries with mass-produced arquebuses began playing a critical role. By the end of the Sengoku Period, several hundred thousand firearms existed in Japan and massive armies numbering over 100,000 clashed in battles; which in turn was a major contributor to the downfall of the classical samurai
The last showing of the original samurai was in 1867 when samurai from Chōshū and Satsuma provinces defeated the Shogunate forces in favor of the rule of the Emperor in the Boshin War (1868–1869). The two provinces were the lands of the daimyo that submitted to Ieyasu after the Battle of Sekigahara (1600).
The samurai finally came to an end after hundreds of years of enjoyment of their status, their powers, and their ability to shape the government of Japan. However, the rule of the state by the military class was not yet over.
The last samurai conflict was arguably in 1877, during the Satsuma Rebellion in the Battle of Shiroyama. This conflict had its genesis in the previous uprising to defeat the Tokugawa Shogunate, leading to the Meiji Restoration.