Just to tack a comment onto David L's exemplary explanation. While sarcasm can be wildly witty, cutting, and funny to all involved except the target, it may be used in a more interpersonal way to mock, hurt, demean, and humiliate, as those who suffered at the hands of a nasty school teacher may remember.
The purpose of irony (as I understand it) is not to hurt or ridicule, but to establish and/or confirm the bond between people by playing on each other's (apparent or real) foibles, and it can be directed by the speaker towards (at least) three targets: (1) directly at the interlocutor, (2) at the speaker and the interlocutor combined, and (3) at the speaker him/herself.
In the first case, often what the speaker expects is an equally witty deprecating retort from the interlocutor, providing the basis for further repartee and establishing or confirming the rapport between the two, as is the purpose in the second case, also. The third case often may involve not only (seriously) tongue-in-cheek self-deprecation but also the fine art of understatement, i.e. the words are the "opposite" of the intended meaning in that they seriously understate the meaning. For example, if you're talking to a pal about breaking up with your partner, you might say that you were "slightly upset, as you can imagine" - in other words, you were heartbroken.
There can be a fine line between irony and sarcasm, however, especially if the target does not accept or perceive (near-)equality or intimacy with his/her interlocutor, in which case what was meant ironically may come over as sarcastic or impudent.
Also, those who have a thin skin and/or not much of a sense of humour are unlikely to appreciate irony.