How to say “hello/goodbye” in Italian

I’ve always found it difficult to fully understand when to use “ciao”, “buon giorno” or “salve”. As I left the bakers yesterday I said “arrivederci” and the 3 assistants responded “ciao”, “buon giorno” and “salve”!

Cheerio for now.