Why do dogs sniff each other?

When you’re out walking your dog you have undoubtedly noticed that dogs sniff an awful lot. They sniff their surroundings, they sniff the ground where other dogs have left a scent marking, they greet other dogs by sniffing their butt, and other equally undesirable areas.

How many times have you wondered why?