According to Men's Fitness there are some important keys to avoiding painful ingrown hairs, which are caused by clogged, oily pores where bacteria grows freely.
You should know that it's most important that you start with a fairly new blade and shave in the direction that your hair grows. Once you get these practices down, here is how you prevent ingrown hairs:
(1) Before you shave, put some warm water on your hair
(2) Put some cool water on your hair after shaving
(3) Exfoliate regularly
(4) Use a Moisturizer after shaving.