Military rank
(National armies were the armies of the kings. Field armies were armies raised by the king to enter the battle field in preparation for major battles.) In French history, lieutenant du roi was a title borne by the officer sent with military powers to represent the king in certain provinces. A lieutenant du roi was sometimes known as a lieutenant général to distinguish him from lieutenants subordinate to mere captains. The sergeant acting as staff officer to the captain general was known as the sergeant major general. This was eventually shortened to major general, while captain general began to be addressed, depending on the military branch, as general of the infantry, general of the cavalry or general of the artillery, and these ones, over time, were shortened to simply general. This is the reason a major outranks a lieutenant, but a lieutenant general outranks a major general.
In modern times recruits attending basic training, also referred to as boot camp by some branches, are instructed in the hierarchical structure of military rank. Many new enlisted civilians find it difficult to understand the structure of general staff ranks as stated before, it becomes somewhat complicated to understand when applying basic rationale.
As armies grew bigger, heraldry and unit identification remained primarily a matter of the regiment. Brigades headed by brigadier generals were the units invented as a tactical unit by the Swedish king Gustavus Adolphus II ("Gustav II Adolf", who was killed at the battle of Lützen 1632). It was introduced to overcome the normal army structure, consisting of regiments. The so-called "brigada" was a mixed unit, comprising infantry, cavalry and normally artillery, designated for a special task. The size of such brigada was a reinforced company up to two regiments. The brigada was a 17th-century form of the modern "task force". In some armies "brigadier general" has been shortened to "brigadier".
Around the end of the 16th century, companies were grouped into regiments. The officers commissioned to lead these regiments were called "colonels" (column officers). They were first appointed in Spain by King Ferdinand II of Aragon where they were also known as "coronellos" (crown officers) since they were appointed by the Crown. Thus the English pronunciation of the word colonel.
The first colonels were captains granted command of their regiments by commission of the king. The lieutenants of the colonel were the lieutenant colonels. In the 17th century, the sergeant of the colonel was the sergeant major. These were field officers, third in command of their regiments (after their colonels and lieutenant colonels), with a role similar to the older, army-level sergeants major (although on a smaller scale). The older position became known as sergeant major general to distinguish it. Over time, the sergeant was dropped from both titles since both ranks were used for commissioned officers. This gave rise to the modern ranks of major and major general.
The full title of sergeant major fell out of use until the latter part of the 18th century, when it began to be applied to the senior non-commissioned officer of an infantry battalion or cavalry regiment.
Regiments were later split into battalions with a lieutenant colonel as a commanding officer and a major as an executive officer.

Modern: Modern military services recognize three broad categories of personnel.
These are codified in the Geneva Conventions, which distinguish officers, non-commissioned officers, and enlisted men.
Apart from conscripted personnel one can distinguish:

Commissioned officers: Officers are distinguished from other military members (or an officer in training) by holding a commission; they are trained or training as leaders and hold command positions.
Officers are further generally separated into four levels:

General, flag, or air officers
Field or senior officers
Company grade or junior officers
Subordinate officer (naval cadet or officer cadet in the Canadian forces, for example)

General, flag, and air officers: Officers who typically command units or formations that are expected to operate independently for extended periods of time (i.e., brigades and larger, or flotillas or squadrons of ships), are referred to variously as general officers (in armies, marines, and some air forces), flag officers (in navies and coast guards), or air officers (in some Commonwealth air forces).
General-officer ranks typically include (from the most senior) general, lieutenant general, major general, and brigadier general, although there are many variations like division general or (air-, ground-) force general.
Flag-officer ranks, named after the traditional practice of showing the presence of such an officer with a flag on a ship and often land, typically include (from the most senior) admiral, vice admiral and rear admiral. In some navies, such as Canada's, the rank of commodore is a flag rank.
In the United Kingdom and most other Commonwealth air forces, air-officer ranks usually include air chief marshal, air marshal, air vice-marshal and air commodore. For some air forces, however, such as those of Canada, United States and many other air forces, general officer rank titles are used. In the case of the United States Air Force, that service was once part of the U.S. Army and evolved as a separate service in 1947, carrying over its extant officer rank structure. Brazil and Argentina use a system of general officer ranks based on the term brigadier.
In some forces, there may be one or more superior ranks to the common examples, above, that are given distinguishing titles, such as field marshal (most armies of the world, notably excluding the United States) or general of the army (mainly the United States because "marshal" is used as a peace officer's designation), fleet admiral (U.S. Navy), Marshal of the Royal Air Force, or other national air force. These ranks have often been discontinued, such as in Germany and Canada, or limited to wartime or honorific promotion, such as in the United Kingdom and the United States.
In various countries, particularly the United States, these may be referred to as "star ranks" for the number of stars worn on some rank insignia: typically one-star for brigadier general or equivalent with the addition of a star for each subsequent rank. In the United States, five stars has been the highest rank regularly attainable (excluding the marines and coast guard, which have traditionally served as branches of the navy in times of war and thus under the command of a fleet admiral). There also exists the specialty ranks of General of the Armies of the United States and Admiral of the Navy which at their inception were considered senior four star officers but came to be considered six-star rank after the creation of five star officers. To date only one officer has held a six star rank in his lifetime, John J. Pershing. George Washington was posthumously promoted to the post in 1976. Additionally, Admiral George Dewey was promoted to admiral of the navy but died well before statute made it senior to an admiral of the fleet upon the latter's inception.
Some titles are not genuine ranks, but either functions assumed by generals or honorific titles. For instance, in the French Army général de corps d'armée is a function assumed by some généraux de division, and maréchal de France, which is a distinction denoting the most superior military office, but one that has often neutered the practical command powers of those on whom it is conferred. In the United States Navy, a commodore currently is a senior captain commanding a squadron, air group, or air wing that is too small for a rear admiral to command, although that name has historically been used as a rank. The title (not rank) of commodore can also indicate an officer who is senior to a ship's captain (since only the ship's commanding officer is addressed as captain while under way). Marine captains are sometimes referred to as major to distinguish themselves while shipboard, although this reference is not employed in the U.S. Navy or U.S. Marine Corps.

Field or senior officers: Field officers, also called "field-grade officers" or "senior officers", are officers who typically command units that can be expected to operate independently for short periods of time (i.e., infantry battalions, cavalry or artillery regiments, warships, air squadrons). Field officers also commonly fill staff positions of superior commands.
The term field(-grade) officer is primarily used by armies and marines; air forces, navies and coast guards generally prefer the term "senior officer." The two terms are not necessarily synonymous because the former is frequently used to describe any officer who holds a command position from a platoon to a theater.
Typical army and marine field officer ranks include colonel, lieutenant colonel, major and, in the British army, captains holding an adjutant's or operations officer appointment. In many Commonwealth countries the field rank of brigadier is used, although it fills the position held by brigadier general in other countries. In the United States Army, warrant officers who hold the rank of CW3–CW4 are field grade officers; CW5s are senior field grade officers.
Naval and coast guard senior officer ranks include captain and commander. In some countries, the more senior rank of commodore is also included. In others lieutenant commanders, as equivalents to army and marine majors, are considered senior officers.
Commonwealth air force senior officer ranks include group captain, wing commander, and squadron leader, where such ranks are still used.

Company grade or junior officers: The ranks of junior officers are the three or four lowest ranks of officers.