First of all, make white vinegar your best friend--she will help you out in so many situations, especially this one!
NOTE: This tip works for both top-loading and front-loading machines.
You may notice that your washing machine has quite a bit of soap build-up or in my case, I just recently purchased a used washer that had come from a home with very hard water and left quite a mess (the tub part and rubber folds were full of what looked like rust).
What you need to do is pour 2-3 cups of vinegar into the tub, and run the washing machine through a complete cycle on the hottest setting to remove odors, stains and detergent build up. If it is really bad, you may wish to repeat this process. DO THIS ONCE A MONTH TO MAINTAIN A CLEAN MACHINE.
For the lid/door, scrub around the edge with vinegar to remove mildew and detergent build up, especially where all the rubberized parts are!
Tips:
*To prevent mildewing, leave the lid open after you finish a load to allow the washing machine to dry out.
*Commerical fabric softeners leave build up in the machine. Make vinegar your fabric softener of choice, and the inside of your washing machine won't need to be cleaned as frequently – if at all.