I think this has been discussed before, you just need to do a search - but:

I think kun is mainly used for young boys, or possibly those who are below you in rank or stature, or those who are younger than you.

San might be used for males or females, it's a general title that is more formal than kun or chan.

Chan is usually used for younger girls, but it can be used for males if the user is a very close friend or just being stupid.

Sama is for someone of high esteem, somebody who is a leader or well respected. Someone of a higher rank than you.

Please feel free to correct me anyone because this is only my own personal understanding of it.