In the Keynesian economic model, we look to government stimulus when unemployment is substantially higher than we think is "normal". There isn't a good underlying theoretical model about what constitutes "normal" unemployment, but we know empirically that if unemployment goes below 4% to 5%, we start getting undesirable positive-feedback effects in inflation. "Too-high" unemployment means that a big chunk of our primary resource — people's time — is simply being wasted.
We also want to see excessive savings: private individuals and companies holding a lot of cash without investing it. If companies are not holding a lot of cash, then we want to look first to monetary policy: we can probably solve the problem by just printing more money. But if companies are holding a lot of cash, printing more money isn't effective: we can expect that if we just create a lot of cash, companies will just save it, since the new fiat money is by definition eroding the value of existing saved money. (We can also tell if savings are excessive and monetary policy ineffective when short-term interest rates near zero, the "zero lower bound"; printing money lowers nominal interest rates, which cannot — for reasons more complicated than I want to discuss, and that I'm not confident I understand completely — fall below zero.)
In a pure Keynesian stimulus, the government borrows money and uses the borrowed money to employ people to do something useless*. We would of course prefer that we do something useful, but the analysis is simpler if we simply ignore the use value of what we use a stimulus to build. Also, if it's justifiable to use a stimulus to do something useless, it's even more persuasive to use it to build something useful.
*Keynes suggested we pay some people money to dig holes, and others to fill them back in.
First, the government borrows $1,000,000 from the private sector when the GDP is $10,000,000: i.e. we're immediately borrowing 10% of GDP. The $1,000,000 is for all intents and purposes stuffed in a mattress: remember, we look to a Keynesian stimulus only when we see excessive saving the private sector. And, since we look to a Keynesian stimulus only when nominal interest rates are low, we can borrow the $1,000,000 at a relatively low interest rate. The nominal 10 year treasury rate, the rate at which the government borrows money from the private sector, is 2.94% as of Friday, July 30; given that we expect inflation to run about 2% per annum long term (one of the effects we're trying to achieve with a stimulus is to raise the interest rate), the real interest rate (nominal interest minus inflation) is 0.94%. The technical term for such a low interest rate is "free money" or "it's raining soup: grab a bucket!" Borrowing $1,000,000 will cost us (assuming the government makes interest payments as they accrue, and we don't compound the interest) a total of 0.0294 * 10 * $1,000,000 + $1,000,000 = $1,294,000.
We spend the $1,000,000 principal over one year: six months to pay people to dig holes, six months to fill them in. So immediately we have raised the GDP by $1,000,000: Our GDP is now $11,000,000, so our deficit is $1,000,000 / $11,000,000 = 9.09%. Furthermore, we collect some of that money directly back in taxes the first year. Figuring a 20% tax rate, we collect $200,000 back in taxes from the workers we're paying to dig and fill in holes. We'll stuff this money in the mattress and use it to make interest payments. So effectively, we immediately reduce our total debt burden to $1,094,000.
But that's not all: we're giving this money to people who are themselves not saving. They thus must spend their money ($800,000) on food, rent, clothes, etc. This spending will raise GDP by $800,000, and the government will receive another $160,000 in taxes. And those getting the $800,000 will spend the remaining $640,000, which will be taxed and itself spent. There's probably an calculus formula that will give the precise answer, but a quick Excel spreadsheet shows that the total effect on GDP will be a few bucks short of $5,000,000, and the government will collect the $1,000,000 in taxes in the first year.
Christianity promises loaves and fishes; socialism delivers them to your door!
Of course this is a very superficial analysis. I'm making a lot of unrealistic assumptions, perfect efficiency, everything spent and consumed in one year, nothing ever saved or taken out in rent and profits, etc. In reality, our 5:1 bang for the buck turns out to be more like 1.2 to 1.5:1 (or so I'm informed by reliable sources). But even 1.5:1 ain't chopped liver: for every dollar spent, we're getting $0.50 in free GDP. And that's not counting what we pay people to actually build. If we're smart, we'll get not just the macroeconomic effects but a bridge, or a road, or a museum, which has social value itself.
Not only that, but injecting $1,000,000 to pay people to do something completely useless changes the money/stuff ratio, which should increase inflation. If we can inflation up to an average of 2% for the 10 years we're holding the loan, our real interest rate becomes 0.94% which is couch-cushion money.
It's important to understand that a stimulus works only when there is a substantial imbalance between savings and employment, low interest rates, and low inflation. When you have full employment, just enough savings to guarantee liquidity, healthy inflation and interest rates, stimulus (paying people to dig holes) has a negative effect on GDP and just wastes money, time and effort.