Where does the government borrow billions from?

How does a government borrow money, and when does it have to pay it back?