The basic principle is simple. When pressing the shutter button, three photos are taken. One photo is normally exposed, another is underexposed, and the third is overexposed. These three photos are combined, on the fly, to create a single image where the overexposed areas of the normal photo are replaced with the areas from the underexposed image and vice versa.
Instead of areas of a photo being too light or too dark, they come out just right.
One downside is that you can't photograph fast moving objects since there will be noticeable movement in the final HDR image. However, Apple's camera app cannot only compensate for this, sometimes, but it also has the ability to take an out-of-focus or blurry photo and, amazingly enough, correct it. Another downside is when you want high contrast in your photo, since the point of HDR is to reduce contrast.
The iPhone gives you the option to save the HDR image, only, or both the HDR and the normally exposed photo. I recommend always saving both to the camera roll so you'll have the option to pick the best one.