Machiavelli was born the son of Bernado Machiavelli, a lawyer,
landowner on a modest scale, and a humanist. Machiavelli received a good education, and was given a post in the government of the republic of Florence.
Florence in the late 15th century was in a state of some upheaval. In 1494, Charles VIII of France had invaded, and Piero de Medici, the unofficial head of the Florentine state, had been forced to flee. With Florence in such a state, their subject city of Pisa, took their chance to revolt, and it would be ten years before Florence regained control. For a short time Florence became a theocracy under Girolamo Savonarola, who didn't last long before being deposed and burnt at the stake. Florence now became a republic, and Machiavelli was appointed second chancellor, a post he held for fourteen years. In this position Machiavelli worked strongly with the executive concerned with foreign relations, which was rather alarmingly named the Ten of War. This gave him the opportunity to travel abroad, and witness the governence of France, Rome and Germany at first hand, an experience he would use in his later works.
Meanwhile, the French presence in Italy remained a threat to the republic of Florence, and also by the presence on their borders of the Duke of Valentino, one Cesare Borgia, the son of the pope. The Borgia threat subsided with a change of Pope, but Florence now found itself stuck between the French and Julian II, both of whom expected loyalty while both becoming increasingly hostile to the other. Florence eventually sided with the French, and were promptly invaded by the Spanish, who had allied with the pope. Florence sued for peace, and the pope insisted that the republic ended and the Medicis were restored.
Giuliano Medici wasted no time in taking power, dismantling the republican institutions, and sacking Machiavelli. Furthermore, when Machiavelli was suspected of plotting against the Medicis, they had him tortured for a while, although he maintained his innocence.
After being released, he retired to his farm, played cards, drank, read and wrote, all the while hoping for a call from the state to re-employ him. It was in this period that he produced his most famous work, The Prince*. At the same time, he was working on his Discourses on Livy, which contains many of the same arguments. In 1520, Machiavelli produced his third major work, his Art of War. However, his obsession with the classical period meant the book was rather outdated even as he wrote it, and he'd decided on his point of view despite any evidence to the contrary. *.
By the mid-1520's, the Medicis under the leadership of Pope Clement VII were more friendly to Machiavelli, and started to employ him again, both as an emissary and to write his last great work, a history of the state. He was later made Secretary to the Procurators of the Walls, in charge of the city's defences. However, when Rome was sacked, Clement VII lost control of Florence. Ironically, having faced not just being sidelined but actually tortured by the Medicis for so long, having finally been allowed back into politics, Machiavelli was now viewed as being too close to the Medicis, and was sacked by the new rulers of Florence. He died in 1527, just missing the long siege that not only proved the quality of the improvements Machiavelli had made to the city defences, but also the restoration of the Medicis.
Growing up at a time when the most admired state in history was the Roman Republic, Machiavelli was essentially a republican, preferring a state controlled by its citizens (note that the citizens would be a small proportion of its population). The decline of Rome was blamed fully on the decadent emperors. Machiavelli had also had the chance to get a close look at the German political scene, and while his opinion of the procrastinating Maximillian was rather low, he did admire the functioning of the German city states, seeing them as retaining some of the merits of the ancient Roman Republic. However, he was also impressed by Cesare Borgia, and used him as a model of a daring leader free of the baggage of idealogy. This was despite the fact that for all his daring, without having his father as Pope, Borgia rapidly lost not just power but his life.
Machiavelli's posthumous reputation has rather suffered due to the tendency to link personal standards of morality to what Marchiavelli was presenting as the science of government*. The term Machiavellian has been used to describe anyone engaging in devious and quite possibly immoral political acts.