Machiavelli served his native Florence as a diplomat and ambassador. Florence was eventually beaten and absorbed by other nations, and Machiavelli was briefly tortured, and then sent to live on his ancestral farm.
Having nothing to do, he wrote a political manifesto in the form of a rulebook for government, The Prince. His contribution to philosophy is mainly that he was the first political thinker and writer to abandon the ideas of morality and ideology and emphasize power for its own sake. The two important things a ruler can have, says Machiavelli, are "Virtu" and "Fortuna"... but it is important to note that by "virtue," he didn't mean it the way the Bible does.