Why Do Dogs Smell Each Other’s Butts?

I remember asking a vet quite a few years back, “Why do dogs sniff each other’s butts?” and she said, “It’s how they get to know each other.” but she didn’t really go into detail about HOW that whole process works.