This has puzzled me for some time. I am wondering what is the german word used for "receipt" when used in a transaction for instance, when paying for a drink in a german pub, which word is written on top of the receipt? Searching in the online pons dictionary I found both the words Quittung and Beleg with no striking difference, so, do they mean the same in this context?
Beleg has a broader meaning than Quittung.
A Quittung is a written confirmation that a payment or some other benefit has been received. There is also a verb quittieren, which stands for writing a Quittung.
Beleg comes from belegen (to prove). A Beleg is a document that proves something. A Quittung is a Beleg, but a Beleg doesn't have to be a Quittung. For example, an invoice can serve as a Beleg (that some goods have been delivered or some service has been provided) but it's not a Quittung because it's written by the provider and not by the recipient.
As mentioned in the comment by "infinitezero", you will ask for the "Rechnung" in a restaurant or pub. You will also get a "Rechnung" in case of buying more expensive items in a shop.
The term "Rechnung" has different meanings depending on the law in which context it is used. In general, most trades require that a "Rechnung" is printed and handed over to the customer. In this terminology, each "Quittung" or "Kassabeleg" must have a unique fiscal identifier in austria (a QR code). Then it can be seen as "Rechnung". In addition, Austrian law and I assume it's very similar in Germany, the clerks define minimum requirements for a "Rechnung" in terms of V.A.T. laws, (e.g. a unique number, address and name of both seller and buyer). This case of "Rechnung" I would translate to "invoice". If you pay cash, then the "Rechnung" is standalone with text remark "paid with cash". If you pay with credit/debit card, the "Quittung" (voucher / receipt for payment) is separately printed and in many cases stapled with the invoice.
But for smaller things you will just get a "Quittung", "Beleg" or "Kassenbeleg" (receipt) which is printed directly from the casher's desk often w/o having payment or buyer information. In some situations this receipt contains all the formal requirements of an invoice, and then the "Beleg" is a "Rechnung".