Your diapers should smell like clean, wet clothes coming out of the washing machine. If they don't, something may be awry with your wash routine. Your usual wash routine for cloth diapers should be reasonably simple - a cold wash with no detergent followed by a hot wash with a small amount of detergent. However, if the diapers are exhibiting a funky odor, either coming out of the washing machine or immediately when baby pees, some troubleshooting is in order.
If the diapers smell like barnyard, they are likely not getting clean enough. Try upping your detergent quantity slightly. Although most people use ~2 tablespoons of detergent, folks with front loaders might need a little less, whereas folks with top loaders may use a little more.
If the diapers smell like ammonia, there's usually detergent residue in the diapers. Run several hot washes with no detergent to remove existing residue, and moving forward, try decreasing your detergent quantity slightly and using a residue-free detergent such as Country Save or Allen's (available as a powder or a liquid). (Note that diapers worn overnight for a full 8-12 hours, may smell like ammonia simply due to concentrated urine. If it's only your night diapers that are stinky, this is normal - just rinse them in cold water in the morning before you throw them in your pail so you're not storing concentrated urine in your diaper pail!)
In all cases, ensure the diapers are encountering enough water and have surfaces on which to rub and move. Check out our High Efficiency Washing Machine Tips for ideas.
Occasional treatment with a product like GroVia Mighty Bubbles may help to pull minerals and gunk out of the diapers to help reset them, or before packing them up to await use by another child. You might also try Allen's Stink Out to remove odors from diapers or other items such as gym clothes and towels. Drying in the sun will also freshen and remove stains.