There are a few keys to getting diapers clean. People differ on exact routines and detergent preferences, but most will tell you you need lots of water, plenty of detergent, a pre-wash rinse and an extra detergent-less rinse, as well as a water softener if you have hard water.

Here is the wash routine we have established over the last 3+ years.

1. Lots of water. Set your washer to the highest load size. If it is a front loader, select the Water Plus setting or add a pitcher of water to the load through the detergent drawer.

2. Warm rinse. Many suggest warm rinse but pee and poo come out of the diapers best when rinsed in the temperature they got on there at, so wash in warm first. I do a quick heavy wash in warm with a warm rinse to get solids out. I add one scoop of Seventh Generation powder detergent to that load.

3. Hot heavy wash. I then do a hot wash with 1 1/2 scoops of detergent on the heaviest setting on my washer- Whites Auto Soak (high agitation, hot water, and a 10 minute soak in the detergent). I also add a capful of Calgon or one scoop of Borax for our hard water.  I sometimes add a few squirts of Bac Out (available on Amazon and at Smiths and Sprouts).
4. Another hot and heavy wash with no detergent. I add another capful of water softener to this step.
5. Throw them all in the dryer (except wetbags and covers, and anything else with exposed PUL) on low heat setting. I love to add wool dryer balls to my loads to help agitate the diapers and dry faster. Try sunning your wet diapers on a clothesline or even just on a window sill. The sun is an incredible bleacher and has gotten even the nastiest stains out of my diapers.
People also vary on their opinions on diapers needing to be stripped. Detergent and bodily fluids can build up and need stripped from the fabrics. Hard water can affect it and some need to add Calgon water softener to their loads to help with an ammonia smell. Some use bleach every few weeks or so, but I just don’t like the smell of the bleach and the thought of it touching my kids’ bums (even when washed many times after the bleach soak). I have had success with original blue Dawn dishsoap. I add a spoonful to the load (after the hot heavy wash with regular detergent) and wash on hot. I then run 5 or so hot and heavy washes with cold rinses to get all the dish soap out. You can be sure the soap is out by checking for bubbling when the wash cycle is agitating.
I never dealt with ammonia build up issues until recently and had to switch from Country Save detergent to Seventh Generation, use more detergent per load, and add a water softener. The ammonia stink has gone away with the soak and strip and the minor changes. See here for more about ammonia and a lot of other helpful tips!
As always, many options and an opportunity to try a few things and find your own way.
Simplified, my routine is:
Warm wash/ warm rinse with 1 scoop detergent
Hot extra heavy wash/ cold rinse with 1 1/2 scoops detergent, 1 cap water softener
Hot extra heavy wash/ cold rinse with no detergent, 1 cap water softener

Dryer on low heat or hang in the sun.

Calgon Water Softener Liquid, 32 Ounce (Pack of 2)

Biokleen – Bac-Out Stain & Odor Eliminator – 32 oz.

Seventh Generation Powder Laundry Concentrated, 112 Ounce