After the crisis of 1513, with arrests for conspiracy, torture and after being sentenced to house arrest, Machiavelli's relationship with the Medici family passively began to mend itself. If the dedication of Il Principe (1513) to Lorenzo II de' Medici had not any effect, part of the then dominant faction of the Florence was not against him, and instead granted him an appointment.
In his letter he deplores his idle state, offering his precious political experience to the new lord. To sustain that timid request Machiavelli, with a considerably courtier-like spirit, set his Mandragola for the wedding of Lorenzino de' Medici (1518). In 1520, he was invited to Lucca for a mission of a semiprivate character, indicating that the ostracism was to be lifted. At the end of that year, Giulio Cardinal de Medici commissioned him to write a history of Florence. Although this was not exactly the charge he desired, Machiavelli accepted it as the only possible way to come back into the grace of the Medici. The intent of the work, although semi-officially, was to recover the city's charge of historic officiality. The wage for the appointment was not large (57 florins per year, later increased to 100).
The finished work was presented officially to Giulio de' Medici, now Pope Clement VII, in May 1526. The Pope liked the work and rewarded him, albeit moderately, and asked him support in the creation of a national army, in the wake of his theoretical work The Art of War, in the preparations for the War of the League of Cognac. However, after the Sack of Rome (1527) and the fall of the Medici government in Florence, Machiavelli's hopes were dashed. Machiavelli would die soon afterwards.
The composition of the work presented a problem, for it was clear that the commission was not meant to give him the opportunity to eulogize the Republic of Florence, of which Machiavelli had been titled "il segretario" (the secretary) par excellence. What was expected of him, if not a glorification of the Medici family, was a treatise without polemics and tending to show the present state of things as a natural evolution. The perplexities of the author leaked through from some letters of his rich collection (to Francesco Guicciardini on August 30, 1524).
The structure of the work, quite contorted, illustrates the difficulty of the author. The first of the eight books is a general picture of the history of Europe from the fall of the Western Roman Empire to 1215; the second book actually begins to discuss the history of Florence, with the narration of the feud between Buondelmenti/Donati and Uberti/Amidei, that according to tradition corroborated by Dante would unchain the conflict between Guelphs and Ghibellines in the city. The books II, III, and IV narrate the history before the Medici rise, while the last four speak of the fight for power that ended with the Medicean lordship. The eighth book closes with the death of Lorenzo il Magnifico, on 1492, with the end of the fragile peace that Lorenzo's politics of balance had carried. The author made an effort to show under an altogether favorable light personalities like Cosimo il Vecchio and Lorenzo il Magnifico.
The first edition was printed in the year 1532.