Seeing as how the job of a washing machine is to keep water and detergent running through it when it's in use, it may seem counterintuitive that you need to sanitize it. But sometimes, your laundry has more than everyday dirt and grime on it.
If you live in a house whose occupants create dirty diapers or have just run through the cycle of a stomach bug, your machine could probably use a once over with some bleach. If you run a natural household, then you may have some issues with using bleach, so be assured that the only time it's necessary to use is when you're dealing with an outbreak of germy proportions. Any other time, plain old soap and water will suffice.
Bleach should be diluted to one part bleach to 10 parts water and it can be stored in a heavy-duty plastic spray bottle. You can start the sanitizing process by spraying the inside of your machine and use a cloth or sponge with some mild abrasion to wipe out any built up grime. Then, spray down the inside and outside of the lid and wipe clean, moving onto the outside of the washer. If you have a front loader, be sure to wipe down the rubber seal well. Then, just run a regular wash cycle on the hottest setting with a cup of bleach. You can throw your rags that you just used in there to avoid a completely empty cycle.