Image caption Painting depicts (l-r) Cesare Borgia, Cardinal Pedro Luis de Borgia, Machiavelli and Micheletto Corella

Machiavelli may have bemoaned his fall from favour in 16th Century Florence, but his enforced departure from politics led to the creation of his great work, The Prince, says Sarah Dunant.

He is a singularly impressive civil servant.

His first job came in '98 after a major change of government. He was still in his twenties and obviously knew some of the right people, but it was also a meritocratic appointment - right from the start he showed an acuity and passion for politics.

Part-diplomat, part-adviser, over the next 10 years he travelled ceaselessly to political hot spots, meeting the players, assessing risk and threat and sending back detailed observations and advice.

The early years of the century were dangerous ones in international politics and his views, though rooted in first-hand experience, were not always listened to by those making the decisions. Looking back, history would prove him right.

But his greatest test by far, was yet to come. In November '12 (1512 that is), Niccolo Machiavelli, having served the Florentine state faithfully for 14 years, fell victim to regime change when the republican government disintegrated in the face of an external coup to reinstate the Medici family.

Yesterday's men became today's enemies. Machiavelli didn't even get time to clear his desk. He was shut out of government and at the beginning of 1513 his name was found on a piece of paper along with others, some of whom were conspirators in an attempted counter-coup.

Arrested, imprisoned and tortured, he spent weeks languishing in what he called a "dainty hospice" with the stench of a charnel house and lice as big as butterflies, listening to the screams around him.

Fate - always a powerful consideration in his political firmament - came to his aid. In Rome, a Medici cardinal was elected Pope and as Florence went mad with joy, he and a number of others were released.

Image caption The view from the Machiavelli family estate in Tuscany

Desperate to re-enter politics but knowing no one was going to employ him, he spent much of that year on the family estate south of the city and it is there, exactly 500 years ago this summer that he started to write a manual of advice on the art of taking and holding of power.

Assessing man's behaviour through history and the bear-pit of Italian politics, he argued that a successful ruler must be able and willing to balance moral virtue with tough, sometimes ruthless pragmatism. Il Principe, The Prince, would go on to become one of the most reviled, studied, admired, influential, read and written about works of political philosophy, securing its writer a place in history that most of the rulers around him never reached.

That, of course, is the judgement of hindsight. For now though, let's stay in that scorching Tuscan summer 500 years ago, a 44-year old man, his arms and shoulders still tender from the strappado (an instrument of torture designed to agonisingly dislocate your arms) sat down to write what he hoped would be his calling card to get himself another job.

Image caption An engraving of the Machiavelli crest

We can, in fact, recreate quite a lot of that moment. The family estate, where he returned to lick his wounds, still exists.

The 1498 tax census describes 60 hectares - about 150 acres - of vines, olives and forest.

The land, now owned by a wine business, stayed in the lineage of the Machiavelli family until a few decades ago and much of the original house has been lovingly restored. The family crest, crossed nails representing the passion of Christ, is engraved on the doors, and behind an old cupboard you can still find the stone basin where Machiavelli would have washed before and after eating.

Though now open to the public, the house is off the beaten track and you need to make an appointment: so that standing inside the vast fireplace staring up into caked blackness or poking your head into the cool of the wine cellar, the imprint of the past feels very strong.

Walk to the end of the terrace and look out over the valley and you can see the top of Brunelleschi's great dome peeking out. How painful it must have been for a man so at home at the centre of things to look down on the city he loved in the knowledge that he was excluded from its government.

Ah, novelist's talk, you're probably thinking - no real history in any of this. Well, yes and no. "I am living on my farm, and since I had my last bad luck I have not spent twenty days in Florence… What sort my life is, I shall tell you."

Machiavelli, like many of his age, was an inveterate letter writer. In the months following that "bad luck", his correspondence is filled with analysis of rivalries between Spain and France (the politician in him never slept), but he also offers more intimate glimpses into his life.

Image caption Brunelleschi's dome on the famous Basilica di Santa Maria del Fiore in Florence

That much-quoted letter, 10 December 1513, to his regular correspondent, Francesco Vettori, ambassador in Rome and a man he hopes will be arguing his case, describes his daily exile: starting with snaring thrushes, then managing farm business, reading a little love poetry by the stream, spending the afternoon at the local inn playing board games "which bring on a thousand disputes and countless insults until we are fighting over a penny". And finally at twilight coming home in every sense of the word.

"At the threshold to my study," he writes, "I take off the day's clothing, covered with mud and dust, put on garments regal and courtly and, re-clothed appropriately, I enter the venerable courts of ancient men, where received by them with affection, I nourish myself on that food which is mine alone and which I was born for, where I am not amazed to speak with them and to ask them the reasons for their actions and they in kindness answer me, and for four hours of time I feel no boredom, I forget every trouble, I do not dread poverty, I am not frighten by death: entirely I give myself to them… and because Dante says knowledge is not produced when we hear but do not remember, I have composed a little work on Princedoms… "

By December 1513 The Prince is finished.

The Borgias A prominent family in political and ecclesiastical life in Renaissance Italy. The family produced two popes - Alfonso Borgia became Pope Callixtus III in 1455 and Rodrigo Borgia became Pope Alexander VI in 1492. Cesare and Lucrezia Borgia - son and daughter of Rodrigo - also gained notoriety as a result of their political manoeuvrings. The family were were suspected of many crimes including incest, murder and treachery. Encyclopedia Britannica In Our Time: The Borgias

Of course, it was not just Machiavelli's intimacy with the ancients - historians of Greece and Rome - that informed his "little work". He also offered examples from contemporary Italy, spotlighting one figure in particular whose mentality and behaviour marked him out for a while as coming close to Principe greatness: Cesare Borgia, the warrior son of Pope Alexander VI.

Machiavelli's observations of Cesare, contained in diplomatic reports of their meetings both at the zenith and the nadir of the young Borgias' comet-like career, are gold standard history.

When in 1502 in a stroke of strategic daring, the young general takes the city of Urbino, Machiavelli and his boss are the first diplomats he entertains. Sitting together in the occupied ducal palace - a renaissance jewel even then - we see though Machiavelli's eyes Cesare's exhilaration, arrogance, intelligence and uncompromising ambition.

They even argue about the best means of government - the Florentines managing to stick up for their republic when their host roundly trashes it. It is as if we are standing in the room listening to them.

Then, less than 18 months later, we are with them again, in Rome this time, where the young Borgia is still recovering from the fever that has just killed his father, and his enemies are swarming like flies around the papal corpse.

Once full of confidence and action, he is now distracted and indecisive. It is as if, as Machiavelli watches, that fierce strategic mind is over thrown by gross misfortune.

More from the Magazine The word "Machiavellian" first and foremost describes a relationship to the works of the 16th Century Florentine theorist Niccolo Machiavelli. But its more common usage relates to the qualities people have gleaned from Machiavelli's The Prince. Scholars have often been vexed by the crude popular interpretations of Machiavelli's work but his supposed ethos has taken on a glorious life of its own in the form of a slew of splendidly devious characters. 10 of popular culture's best Machiavellian characters

Among the many things he takes from the study of Cesare Borgia, the power of fortune stands out clearly. While risks are necessary for success, a cruel turn of event can destroy the strongest of men.

Over the years since his death, many have speculated on whether Machiavelli's political pragmatism is somehow godless - his notion that virtue must in the end be subservient to expediency. Whatever the nature of Machiavelli's private faith it is clear that he - like many of his contemporaries, Cesare Borgia included - was also enthralled to the goddess of fortune.

But then, by the time he sat down to write The Prince, she had just played a dramatic part in his own life.

It was the late Enoch Powell, a controversial politician himself, who wrote "all political lives end in failure… that is the nature of politics".

In fact the original quote contains a sub-clause - "unless they are cut off in midstream at a happy juncture".

"I love my native city more than my own soul," Machiavelli wrote towards the end of his life. Yet despite dedicating The Prince to a prominent member of the Medici family, he was never rehabilitated into government. He was given the odd diplomatic mission, yes - but mostly he remained the observer, travelling, commentating and writing on war, history and human nature.

While no-one, least of all him, would have called that cruel blow of fortune a happy juncture in his life, it resulted in one of the most provocative and influential political best sellers of all time.

Sometimes getting the sack is the best thing that can happen to a man.

Quotes taken from The Letters of Machiavelli, by Allan Gilbert, published by the Chicago University Press (1961)

You can follow the Magazine on Twitter and on Facebook