When you do not follow suit and play a card of a different suit you have discarded. However, this is illegal if you have a card of the suit led, as I am sure you realise, and you are said to have 'revoked' (or 'reneged', to use an old-fashioned term). Revoking deliberately is very serious, but very rare: everyone revokes occasionally by accident.
Let us suppose you revoke: what next? First we check whether your revoke is 'established'. When you or your partner play to the next trick the revoke is established, and penalties come into force. Also, a revoke is established if you or your partner claim, or accept an opponent's claim.
If you realise you have revoked before it is established, you must correct it. You replace the revoking card with a legal card. Any cards played by the other side after the revoke may be changed. If the next player does withdraw his card, and your partner played after him, then he may withdraw his card, too.
While there is no penalty for an unestablished revoke, if you are defending then any cards withdrawn by you or your partner become major penalty cards. They must be left on the table and played at the earliest legal opportunity (there are also lead penalties, as associated with any major penalty card).
Phew! This is getting complicated! Do you have to learn this? The answer is no, thankfully. At duplicate, you call the Director and let him sort it out. At rubber, in a club there is usually a host to do the same thing. When you play in casual rubber games, or private matches, it is a good idea to have a copy of the Laws, or the Yellow book, Duplicate Bridge Rules Simplified - or even a copy of this article - and then sort it out between you.
Anyway, suppose the revoke is established: what then? It is not corrected and the hand is played out. When it is finished a penalty is applied of 0, 1 or 2 tricks. Consider the revoke trick and those after: if the revoking side won none of them there is no penalty: if the revoking side won one of them the penalty is one trick transferred to the other side at the end of the hand.
What if they won two or more? Now it gets complicated! If the revoker (not his partner) won the revoke trick then the penalty is two tricks. If the revoker (not his partner) won a later trick with a card he could legally have played to the revoke trick then the penalty is two tricks. Otherwise the penalty is one trick, all these penalties being transferred to the other side at the end of the hand.
Please tell me there is no more! Oh dear, there is! Suppose your opponent revokes: this costs you a trick, but as the penalty is two tricks, you have gained. This sort of gain is needed to persuade people not to revoke.
Now suppose he revokes, it costs you a trick and the penalty is one trick. Then you have no gain, but equally no loss. This is quite common: it is just luck whether there is a real penalty or not. I know some people argue that this is unfair, but random penalties are common in many walks of life as an effective controlling method, and it seems fair to me.
However, consider the case where a revoke costs you two tricks and the penalty is one trick. Now you have lost a trick which is definitely unfair. But the Law allows you to get that back: you cannot actually lose by a revoke - though you will not necessarily gain from it, either. If an opponent's revoke has cost you any number of tricks more than the penalty, you get them back. It is possible to lose a lot of tricks, for example, when a revoke stops dummy's suit running. Do not worry: you will get them back.
Let us see how that works with an example. You are playing 3NT and this is how the club suit is divided:
There is no outside entry to dummy, but clubs break 3-2 so there are six tricks available. However, the defender with J97 accidentally plays a heart on the first round of clubs, so he wins the fourth round. Let us say he takes the rest of the tricks. According to the rules above, you get two tricks back because the revoker won a later trick with a card he could legally have played to the revoke trick - but that costs you three tricks, which is not fair! This is where the special rule comes in, and you are given your three tricks back.
If ever you feel that you have actually lost more tricks than you are given back by the penalty, ask the Director or Rubber host to have a look at it.
You do not have to draw attention to your own revoke if you first notice it when it is established, but many players do. Do not worry though if your opponents do not draw attention to their revokes.
Duplicate Bridge Rules Simplified [the Yellow book] is published by Mr Bridge