The Chronicle of irony and sarcastic humour:
There's two main types of bad sarcasm.
The first kind is where no one knows you're being sarcastic. This lands you in a real life Poe’s law where you need to convince people after the fact you were being sarcastic. Not funny.
The second kind of bad sarcasm is where you need to completely change the way you say something just so people know you're being sarcastic.
True sarcasm, the mastery of sarcasm, is where you are able to make it obvious you're being sarcastic, while saying it like you're serious.
The only other thing to master once you've got that is targets. Be sarcastic towards someone who you know is going to not only get your sarcasm, but find it amusing. If you can insult someone and make them happy at the same time, you've got it.
Irony is a form of humour that in a funny way describes a situation in which the outcome is opposite to that which was expected. It is often used as a tool within a satirical or sarcastic construction.
Satire is a means of humorously ridiculing a group of people by mimicking their activities in a way that reveals and exaggerates their faults and flaws.
Sardonically a form of mocking insult, it is a cynical, disdainful jibe.
Sarcasm is a form of insincere speech which on the face of it appears to suggest one thing whilst quite clearly implying another. Sarcasm critically relies on its delivery to be effective.
So irony is a humorous incident, sardonic a contemptuous disdain and satire and sarcasm are humorous constructs that may make use of irony and sardonic phrasing.
Any and all can be used in conjunction with each other; a satire can make use of irony and sarcasm, a sarcastic response can be based around a satirical concept.
When using sarcasm there are critical factors that must always be considered. The first to understand is that while sarcasm is fundamentally an insincere response or proposal, it is most effective when all parties (though not necessarily the target) are aware of its underlying truth. So it has to be sincere in its insincerity; you are deliberately lying and letting others know that you’re lying.
The second point and one that requires practice, a certain amount of acting skill and a little mischief is the delivery. Without a polished delivery, the sarcasm, however well thought through and funny, will fall flat on its face and its user open to ritual slaughter. The traditional, ‘true’ delivery is a deadpan, matter of fact response without inflexion or emotion (Basil Fawlty), this has over the years been added to by an overly polite, courteous and brightly positive version that embellishes and exaggerates the point being made (Blackadder). Finally there is a self-pitying, defeatist declaration of the situation one find one’s self in (Victor Meldrew). Both can be either abrupt or quite verbose, it doesn’t matter and should be tailored to suit the occasion.
The third point and one that would seem obvious is that it has to be funny.
Do not over use sarcasm as this will dilute the overall effect, but do use, as explained with satire and irony or preferably a sardonic and pithy riposte.
Finally and crucially it ‘really’ should be used with care as, if used with an overly aggressive or insulting manner and without fair consideration and compliance for the chosen target it can become too hurtful and a device more typical of bullying.
As outlined by Jake Williams in his answer ‘If you can insult someone and make them happy at the same time, you've got it’.
P.S : Sarcasm can be dangerous, try at your own risk! (Saying this from my personal experience)