And it's a good question.
This is how I understand it, but I'm no expert on this and could be wrong.
The answer is a bit involved and needs a bit of background ... so grab a coffee ...
In the UK the Bank of England is responsible for the money supply. Basically the number of pounds that are out there circulating around. The money in your pocket, and the money in your bank account.
The government has a bank account which they use to pay for their goods and services. Think of it that each month this account gets topped up with all the tax revenues (VAT, income tax, etc.) and then the money is spent on paying the salaries of civil servants, buying new PCs, building hospitals, feeding criminals or it's just given away through the benefits and social security system.
At the moment in the UK our government spends something like £80 billion a year more than they take ... the so called structural defecit. As an aside, don't confuse this with the national debt, which is something like £800 billion ... and will get £80 billion a year more until the defecit is sorted out. Once the defecit is dealt with, as a country we'll still be almost a trillion pounds in debt, but at least we won't be getting in any deeper!
When the government wants to borrow money they issue bonds. To anyone non-financial, this is just another term for the government taking out a loan. These bonds are bought by investors (usually referred to at gilts), or banks, or other countries, or pension funds, or anyone else who will buy them. The trouble is that as the government issues more and more bonds to borrow more and more money, the price they have to pay for that borrowing (the interest rate) creeps up.
All this money is kept well accounted for by the treasury and the Bank of England. When the government issues bonds they don't actually create any new money. They get more money in their account, an asset, but at the same time they also have a loan they have to repay, a liability, and the two net out to zero.
When the situation gets dire enough to warrant some new money being printed, here's how I *think* it works, although I'm not 100% sure.
It's more or less the same process in that the government issues some bonds. These bonds are bought by the Bank of England rather than other investors. So the goverment gets the money and the Bank of England gets an I.O.U. To the Bank of England, these bonds (the I.O.U.) are an asset as effectively the UK government now owes them the money. But the Bank of England then cancels these bonds by simply increasing the number of pounds that are in circulation. The Bank of England effectively owes (in theory) one pound to each and every person who holds a pound coin (take a note out of your pocket and you should somewhere see the phrase 'I promise to pay the bearer on demand the sum of ...') They remove that asset (the government bongs) from their balance sheet but at the same time they have to remove some liability as well to keep everything in balance. To remove some liability they 'print' the same number of pounds (it's done electronically, nothing physically gets printed) so that there are more pounds in circulation. Because there are now more pounds, each one becomes worth just a little bit less. Effectively the Bank of England devalues all of our pounds by just a tiny little bit in order to create enough leftover to net off against that government debt that they have just bought.
At that point the theory is that the government spends this money on the salaries of civil servants, new hospitals, train lines and some Post-It notes for the stationery cupboard. The folks building the new hospital treat themselves to a night out for a slap up meal or perhaps even a new car. All this spending gets taxed and so the government's tax receipts increase. This creates growth within the economy and everyone's a winner.
Except for everyone who has just had all their pounds devalued just that little bit. While we don't notice any difference here in the UK (a pound is still a pound, right) that same pound is now worth just a tiny bit less elsewhere in the world. In theory at least. As pointed out above by KG ... the practice doesn't always go the same way as the theory.
I'll now caveat all the above by saying that it's a while since I last did any of this so I invite corrections to anything written.
Bookmarks