Sacrifice peices when there's nothing better to do.
When to sacrifice pieces?

Sacrifice if it will win you material (I know it sounds weird, but a sac can lead to material gain), gives you a mating net that is unstopable, prevents your checkmate (If you would rather play a game to its end than resign), prevents the loss of a piece worth more (sacrifice a knight to save a queen, etc.), or creates a position that is better for you than it is for your opponent.
When should you sacrifise chess pieces? Giving tips would be helpful and showing some examples of when a sacrifice was done. Thanks.