I like to run a "Clean" cycle through my wash machine about once a month.
What you need:
1 cup baking soda
3 cups vinegar
Set your washing machine to the largest load available, and the hottest setting. When the tub of the wash machine is about 1/2 full, add your baking soda, and your vinegar. Allow it to run through a full cycle. When the cycle is finished, run a "Rinse" cycle, by leaving the wash machine settings and running a cycle of clean water. Your machine will smell fresh, and those musty odors that sometimes sneak up, will gone.