Dogs roll on their backs for many reasons, from scent marking to showing submission. Context clues and general body language can help humans determine why dogs are rolling on their backs.
When dogs roll in smelly substances, they are trying to get the odor all over their bodies. Wolves use this behavior to convey information about their territory to the other members of their packs, and dogs retain the instinct. Many dogs find rolling on their backs to be comfortable, so they may relax in that position or actively roll around to scratch themselves. Some dogs roll on their backs while being petted because they enjoy belly rubs and want to provide access. It can also be a playful behavior or an attempt to appease humans or other dogs by showing submission.