Buses, underground trains, S-Bahn trains and trams (in some cities they are called "Straßenbahn") are part of "public transport". To use them, you have to buy a ticket.
Ticket machines may look different in every city. In many buses, drivers sell tickets directly, but only for cash. In many buses, you can only pay with coins or small notes (€ 5 or € 10). With larger ones, it may happen that the bus drivers cannot give you change. Tickets are also sold at some kiosks or in select shops, which you can recognise by the symbol or logo of the transport company of the respective city. In some cities, you can also buy tickets using a specific mobile app.
There are different types of tickets. Some are valid for a few hours, either for a one-way trip or for return trips. Some others are valid for a day ("Tageskarte"), a week ("Wochekarte") or a whole month ("Monatkarte"). Furthermore, there are different "Tarif zones" which indicates how far you can travel with a ticket.
When you buy a ticket valid for a few hours or a day, in many cities, you will have to "validate" it at specific machines available on train platforms. You can also find these machines inside some buses or trams. If the date and time stamp already exist on a ticket, usually there is no need for validation.
Children, pupils, students, senior citizens and people who receive benefits from the Social Welfare Office or Jobcentre, can profit from discounted public transport tickets. You can buy these discounted tickets at the machine or in the designated shops. There, you can also inquire about the document(s) you need to present to buy a discounted ticket.