On one level it's very simple: if you will be better off when it's time to pay the loan back than you are when you borrow it, then borrowing is a good idea. But behind that simplicity lurk many complications...One of these complications is the question of interest. If you borrow at interest, you not only have to be better off when you repay than you are now, but so much better off that you can afford to pay the interest as well.
We can start with student loans. The idea is that you can't earn a very high salary without a college degree, so tuition, room and board would be a big chunk of your income (if any). But with a college degree - so the theory goes, at least - you will be earning a lot more than without one, and the loan payoff (even including interest) will be a much smaller percentage of your income.
Business loans are similar. You borrow money to pay for a new refrigerator for your deli, and then you sell more cold food and drinks. That increased income pays the loan and the interest. This can be true for Starbucks opening a new store, or Bombardier building a new factory.
John Maynard Keynes argued that when individuals and investors are afraid to borrow that way, government borrowing can play the same role. In a recession, tax revenue is low. The government borrows and spends the money on social services and putting people to work. Those people spend that money on food and other necessities, which puts more people to work. Eventually the economy gets going again and people start borrowing and spending on individual and corporate levels.
The genius of stimulus is that just like student and business loans, it can pay for itself. Every time someone earns that money, they pay a percentage of it back in income taxes. Every time they spend the money on taxable goods and services, they pay a portion of it in sales taxes. The same is true for the additional money that gets borrowed and invested as the economy grows again. Government revenues are higher when it's time to repay the debts.
The most tricky part is of course knowing whether you will be better off in the future. No one can know exactly what's going to happen. You may never be better off than you are now. You could be worse off.