Machiavelli wrote The Prince after losing his job, not while holding power
For fourteen years Niccolò Machiavelli ran diplomacy and raised a citizen militia for republican Florence. When the Medici returned in 1512 he was sacked, wrongly suspected of conspiracy, tortured and released. Out of office he wrote The Prince, whose advice to rulers made his surname a byword for ruthlessness.
Machiavelli was born in Florence on 3 May 1469, first son of the lawyer Bernardo, whose illegitimate birth barred the family from full citizenship. At eight he saw the aftermath of the Pazzi plot against the Medici, and as a young man he heard Savonarola preach without being persuaded. Shortly after Savonarola was burned in 1498, the 29-year-old Machiavelli, with no legal or official experience, was made head of the second chancery and secretary of the council for war and diplomacy.
Under the republic's leader Piero Soderini he became an indispensable fixer, sent to the courts of Louis XII of France and Pope Alexander VI's son Cesare Borgia. He admired Borgia's drive and recorded how Borgia trapped and killed rebellious commanders at Sinigaglia on the last day of 1502. He also watched the 1503 conclave elect Julius II, the Borgias' rival. Convinced mercenaries were unreliable, he raised a citizen force; by February 1506 some four hundred armed farmers paraded in breastplates, and in 1509 his troops took Pisa.
Success collapsed in August 1512, when Spanish troops backed by Julius II defeated the Florentines at Prato and the Medici returned. Soderini fled. Machiavelli, whose name appeared on a list of possible plotters, was tortured with the strappado, denied everything, and was freed after three weeks under Pope Leo X's amnesty for political prisoners. He then turned to writing.
The Prince, drafted around 1513 but printed only in 1532, told rulers they might need to do wrong when necessity demanded, and suggested founders of states could be excused for killing opponents. Critics from its first appearance saw a tyrant's handbook; Leo Strauss still called him a teacher of evil. Yet his Discourses on Livy, composed around 1517, helped lay foundations for modern republicanism and influenced Rousseau and James Harrington. He died on 21 June 1527.
Source: Niccolò Machiavelli