OK, your dog's anal glands are not a pleasant topic for anyone. So, we are going to get in, get some useful information, and get out as quickly as we can. And this is some really gross anatomy we're talking about so you're probably gonna want to put down that sandwich.
Anal glands are two sacs about the size of small grapes on both sides of your dog's anus, just under their tail. Genuine apologies if that ruins grapes for you. These sacs are filled with an oily substance that smells kind of fishy, or kind of skunky, depending on who is doing the sniffing. Presumably to dogs, it smells terrific.
Science hasn't pinned down exactly why dogs have these glands at all, but they do seem to serve a few purposes. They likely lubricate the pooping process and disperse their scent for marking purposes. It's also possible that the glands diffuse pheromones to communicate with other dogs (hence the reason they sniff each other's butts).