Here are some tips to help prevent ingrown hairs when shaving:
1. Exfoliate before you shave. Use an exfoliating scrub that has a moisturizing oil base. This will get rid of dead skin cells and moisturize the skin so that the razor can glide smoothly over the surface. 
2. Dry hair is far more likely to cause ingrown hairs or razor bumps than wet hair. Because of this, you should always wet shave. The best time to shave is either in the shower or directly after a shower since the water will help soften the hair and make it more pliable for a gentle shave.
3. Always use a shaving cream, lotion or gel. Lubricating the skin will help the razor move more smoothly over the surface, preventing nicks and razor burn.
4. Shave with the grain of the hair rather than against it. Although you won't get quite as close of a shave this way, it will minimize the chance of getting ingrown hairs. If you absolutely insist on getting a closer shave, you can do a single pass against the grain after the bulk of the hair has been removed. Just be sure to use light pressure and to apply fresh shaving cream to make it as easy as possible to move the razor across the surface of your skin. 
5. Use short strokes rather than long strokes. This will keep the razor from getting clogged up with hair and dead skin cells.
6. Rinse the razor frequently to remove any hair that has become trapped between the blades. The cleaner your razor is, the more cleanly it will cut the hairs. Again, this can reduce the risk of winding up with ingrown hairs.
7. Only shave with a sharp blade. This will cut the hair off cleanly, allowing it to grow back out again without getting trapped under the skin.
8. For areas of the body where chaffing or rubbing may occur, apply talcum powder after shaving. This helps keep the area dry, which in turn can prevent hairs from growing into the skin.
Here are a lot more tips for preventing ingrown hairs: