A mixture of baking soda and white vinegar is the best way to clean and remove bad smells from both top-loading and front-loading washing machines. Using 2-4 cups of white vinegar and 1/4 to 3/4 cup baking soda is an ideal mixture.
The bad odors that machines acquire over time are due to the build-up of dirt and enzymes left behind after washing clothes. Also, some water is left in the machine after use, which allows mold and mildew to grow. Using the baking soda and white vinegar mixture cleans and deodorizes the machine and kills the mold and mildew. Leaving the lid or door open between uses can help the machine dry out, which prevents mold and mildew.