I'm trying to wrap my head around why states and leaders relied on mercenaries. There is this trope that they are purely profit-motivated and consequently untrustworthy and unreliable. Is that accurate? If so, what determined the choice to make use of mercenaries? How were they efficiently used? Why did they fall out of favor (among European states/leaders)?
I can answer some of those questions on the example of the thirty years war, which was almost entirely fought by mercenaries.
Since there were no standing armies in 17th century Germany, rulers had to hire mercenaries to fight their wars. That was done through an "Obrist". Basically the leader gave the Obrist money, which he used to hire mercenaries. The most famous example of an Obrist is probably Wallenstein, who gained enourmous fortunes and power during the war. In face he became so powerful, that the Kaiser regarded him as a danger and had him killed.
Mercenaries in the thirty years war were not loyal to the state for which hired them, but to their Obrist. It was a common occurence that captured mercenaries switched sides after a lost Battle. An example: Gustav Adolfs army was bigger after the battle of Breitenfeld than before. It was so common that they did not have to fear repercussion should they be captured again by their original side.
Those mercenary armies were fairly reliable, as long as they got paid. They had to turn to other ways once the money stoped flowing, mostly getting their basic needs from the civilian population, which was resulted in misery for the common people, who were terrorized, pillaged and raped by slightly less poorer mercenaries. About one third of the German population died drung the war.
The rulers faced an other problem after the peace of Westphalia: They simply did not have the cash to pay off their mercenaries. Not paying them would have resulted in even more misery for their population, so some simply hired them as a standing army.
A few years ago, someone found the diary of a common mercenary, buried deep in the Berlin archives. It´s a unique source that gives us insight into the life of mercenaries. You should be able to find it if you google "Peter Hagendorf".
Please excuse my english, it´s not my first language :)
Sometimes countries were simply too small to combat countries with far larger populations. For instance during the 1600's the United Provinces only had 1.5 million people in its population compared to the 10 million (Spain) and 20 million (France) they would be warring against for the next hundred years.
This left them in a huge need for more manpower, in this case they tried keeping the amount of mercenaries above the Army of Flanders (the Army of the Spanish Netherlands). Which was around 60 thousand troops. When fighting France though, the Netherlands upped it to around 90 thousand to France's army of 280 thousand. The difficulty France had, caused Austria and Spain to join the war on the United Provinces side. (The Army of Flanders and the Spanish Road: The Logistics of Spanish Victory and Defeat in the Low Countries' Wars, Geoffrey Parker)
Another reason could said is that certain groups were famed for being good in battle such as the Swiss, Croatians, Serbians and Cossacks. The Swiss is a notable example after the Italian wars, as they were used by the French extensively (where maybe up to 120,000 Swiss mercenaries participated) as well as becoming guards for the Pope during the Sack of Rome (causing Swiss guards to become the guards of the Pope ever since) and under Savoy.
The reason usage dropped was because it stopped being as effective as was shown and said by Napoleon. "The Greeks in the service of the Great King were not enthusiastic in his cause. The Swiss in French, Spanish, and Italian service were not enthusiastic in their causes. The troops of Frederick the great, mostly foreigners, were not enthusiastic in his cause. A good general, good training, and good discipline make good troops independently of the cause in which they fight. It is true, however, that fanaticism, love of fatherland, and national glory can inspire fresh troops to good advantage."
This was the opposite in the case of Prussia, which is said to have around half of its troops being mercenaries at the time of the Napoleonic Wars and is sometimes seen as why they lost.
Why they were used: Mercenaries were used a lot by city states rather than larger empires (although larger nation-states did employ them from time to time), mostly because it was a way to garner force-projection on the regional scale. If you are Venice, or Florence, or any other Italian city state, what kind of population do you have compared to say, the Kingdom of Naples, or France, or Spain? In reality, how many able-bodied, fighting age men do you possess, even if you put out a general call to the countryside. You couldn't match the standing armies of these larger nations. However, you are very wealthy through trade (or in some cases just personal fortune), so you can buy an army. You know these soldiers have no allegiance to you aside from the money you pay them, but as long as you pay them well, they perform well, as they are professionals, and if word gets out that they didn't perform their duty, no one would hire them. In addition, they are quite skilled, as they do this for a living, and would likely see more combat than your average soldier in a large nation's standing army.
How were they used: In the example above, they were the bulk of the army. In an example of a larger nation still employing them (for example, the British in the American Revolution hired the Hessians), they would serve some specific purpose. Either the job was unique, or dangerous, or the empire simply needed more troops if they were fighting a large enemy or multiple enemies.
Why they fell out of favor: The quality of mercenaries diminished compared to the value of having large, well trained standing armies, especially as city states made way to nation-states. Furthermore, in the high times of mercenaries, it was considered a profession, it was your job and you would treat it as such. Later on, these professional groups (The Hessians are a prime example), joined some nation state somewhere, and were no longer for sale. Today however, we see a small uptick in mercenaries, as the US military for example routinely uses the services of private military contractors, mainly for defensive operations. They are used for supply protection, and VIP bodyguarding, etc. This frees up the military for more military-minded operations: search and destroy, objective capture, hard-target destruction, etc.