Especially when you really like the people you work for and know they'll be in a bind without you there, after going through training, etc.
Depends on WHY... if you like the people and just hate the job, then you sit down with your supervisor and explain that everyone's been great but you just don't feel like the job is a good fit and you're sure the company would benefit more with someone taking over the position that was more suited to it than you are.
If it's for personal reasons, you apologize profusely about the fact that you must give notice due to a change in circumstance at home.
If it is that you've just been offered the job of your dreams, again apologize profusely but explain that you just cannot pass on this opportunity, if possible offer to stay on until they've found a replacement.
I've had to do this three times and two out of three employers genuinely wished me well and all three still offer me good references.