When you buy a bond from a company or a government, you lend them money, i.e. you give them a loan.
Symbolically speaking, you get a piece of paper that says you have lent money to a company or government and will get it back at the end of a fixed period. Plus interest. These interest rates vary and depend, amongst other things, on the current key interest rate in the economy and the risk that you as an investor are taking by lending your money.
There are two different types of bonds.
Government bonds
Governments issue bonds in order to have more money at their disposal. The government uses the money from investors for infrastructure projects or the repayment of old debts, for example. By purchasing a government bond, the investor makes money available to the government for a limited period of time.
Corporate bonds
Corporate bonds are issued by companies to increase the amount of money they have available to invest in their own interests. For example, this could be put towards the construction of new factories, research & development or the repayment of old debts. By purchasing such a bond, the investor provides the company with money over a fixed period of time. In return, the investor usually receives their invested money in addition to an annual return at the end of the investing period. This duration can range from a short period such as a few years to a term of over 10 years. The financial situation of the company, the amount of debt and also the economic conditions can affect how creditworthy the company is deemed to be.