Whenever you are going to paint newly installed sheet rock, using a primer is essential. New sheet rock that has been skim coated with joint compound leaves a very absorbent surface which will require several coats of paint if you do not prime it first. If you use a good quality primer before you paint, the primer will seal the pores which will require less top coats of paint. Doing this will also leave a much nicer finish and create a stronger bond between the drywall and your paint.
Next, if you have walls that are stained with water spots, grease or other markings using a oil based primer before you paint is necessary. If you don't use a primer first before you paint over stains, the stain will bleed through your fresh paint. Additionally, smoke or cigarette stains must also be primed first. Not only will these types of stains bleed through your new paint but also the odors from smoke or cigarette stains can often be noticed if not primed first. If you have only one or two stains on your wall then you can just spot prime those stains in lieu of priming the entire room.
Also, if you are changing colors and the color that you are changing to is vastly different, then I would recommend using a primer first. If you prime your walls first, it will again require less finish coats of paint. You can have your primer tinted to your new paint color which will also help by requiring less finish coats of paint.
If you have any mildew on your walls you will need to prime these areas also. But, before you prime mildew stains you must first clean the mildew stains using household bleach and water. Make a mixture of about 10 parts bleach to about 90 parts water and apply it with a rag or sponge to all areas which has visible mildew. After the primer has completely dried, you can then prime this area.
As a general rule, if you are going to paint any surface which has never been painted before, then you will probably need to prime first.. Any metal surface will require a primer in order to create a bond between the metal and the paint. Using a primer will also help in protecting the metal surface from corrosion and rust. Any unpainted wood will require a primer as well. If you fail to prime unpainted wood the paint will begin to peel in a short time. Priming creates a seal between the paint and the wood which will enable it to bond. This is also true for other unpainted surfaces such as brick, stone or concrete.
Primers are available in both oil based and water based. If you are going to use primer to cover any stains or unpainted surfaces, it is a good idea to always use an oil based primer.