How does it get dirty?
The skin cells, dust mites and stains from clothes can linger in a washing machine drum as well as on the lid or door and detergent dispenser. This leads to washing clothes in dirty water, and eventually they'll turn smelly.
How to fix it?
For a top-loading washer, start it on its longest and hottest wash setting. When the drum is nearly full of water, pour in 1 liter of vinegar and 1 cup of baking soda, leaving the lid open and allowing the mixture to sit in the paused cycle for at least an hour. While the cycle is paused, clean the lid and any other visible nooks and crannies. Close the lid, allowing the wash cycle to run. Repeat vinegar and baking soda wash, if needed, then wipe down the inside of the washer and leave the lid open to allow the washer to dry completely.
For a front-loading washer, pour a solution of 1/4 cup each baking soda and water into the detergent compartment and pour 2 cups of vinegar into the drum. Set your machine to the hottest temperature and let it do its thing. When the cycle is over, wipe the drum clean, along with the door, detergent compartment and exterior. Pay extra attention to the gasket. Remember to leave the door ajar between loads for the best air circulation.
Source: excerpt from Family Handy Man