The gambler's fallacy is the incorrect belief that the outcome of any particular event in a series of identical, independent events which have outcomes of a fixed probability, is influenced by the outcomes of previous events in that series.
Take a coin toss for example. If we toss a coin spinning into the air and let it fall to rest on a hard surface, that is an event. This particular event has two possible outcomes, heads and tails. Both outcomes have the same probability of happening (there is nothing to favour one or the other), and that probability is 50%. In a series of coin tosses, the probability of each outcome is the same for each toss (fixed probability). That is true regardless of the results of the previous tosses (independence of events).
We tend to believe that a string of heads, for example, somehow makes it more likely that the next toss will produce a tail. The longer the string of heads, the more we will tend to think that the next one's got to come up tails. This tendency in thinking is general and fairly strong, and may be more the result of 'gut feeling' than rational thought. It is rooted in a common misunderstanding of probability and statistics, in the way the brain works, and in belief in luck (which might be considered a kind of folk theory of probability).
Probability theory tells us that for a very long series of coin tosses the number of heads will be nearly equal to the number of tails, and that the higher the number of tosses, the more nearly equal will be the cumulative numbers of heads and tails. Most people understand that quite well, and it is quite intuitive even for those who have not studied the theory. The problem arises when we apply this long-term 'balancing out' effect to the short term. If this balancing effect were strictly true in the short term, we could predict that a toss that came up heads would certainly be followed by a tails on the next toss. It just doesn't work that way1.
The human brain, like all brains, functions generally as a pattern recogniser. The basic value of knowing the world around us is to be able to predict events and thus increase our chances of survival. So recognising patterns in space and time is a crucial ability. It is also a sub-intellectual process whose result usually comes into our consciousness automatically or as a 'gut feeling'. The brain is very good at pattern recognition, but the problem with applying pattern recognition to a sequence of random events of fixed probability is that there is no pattern to be recognised. The sequence of toss outcomes is chaotic and therefore unpredictable. Seeing a string of ten heads in a row might lead one to bet that the next will be a head too, because a pattern has been established. Alternately, one might be inclined to bet on a tail, because experience has shown that long strings are an abnormal (infrequent) pattern. Both are wrong thinking (or feeling) because the probabilities of the outcomes on the next toss are always 50/50.
Then there's luck. A person's sense of luck, good or bad, is hard to explain, but it seems likely to be connected to those sub-intellectual or even subconscious feelings that result from our brains' attempts at pattern recognition.
The psychological need for gratification may also be a factor. The gambler's fallacy is seen in people's feeling of luck, too. After a run of 'bad luck', many people will develop a strong anticipation of imminent 'good luck' and decide to continue playing, thinking 'I can't lose this time'. After losing again, that feeling only intensifies, compelling the player to continue, and even raise the bet. After a string of successes, however, many people will also continue playing, thinking that they are 'on a roll' and can't lose.
Casinos make tons of money2. Remember that in games of luck where the probability of winning or losing on each bet is the same (roulette, slot machines, etc), it does not matter how many times you've won or lost in the past sequence of bets. The probability of winning or losing the next time is exactly the same. History simply does not affect the outcome. If you find yourself acting as though it does so, you have been duped by the gambler's fallacy.