How can i prevent razor bumps?

Every time I shave I get really bad razor burn and ingrown hairs. How Can I prevent this?