To rephrase what AnnaS. just said:
it's the same as the pronunciation rule for c.
Soft before e and i, hard before a, o, and u.

That's not to say there aren't exceptions--this is English,
after all.