Snakes of the species which prey on other snakes may bite their own tail if they are kept in too small of an enclosure. In these cases, the snake confuses its tail for a separate individual. Snakes may also confuse their tail for prey if they are stressed or overheated.
This peculiar behavior, though rare, has been observed both in captivity and in wild snakes. Rat snakes in particular have been observed attempting to consume themselves. Rat snakes do not typically prey on other snakes, so their tail-biting may be due more to poor eyesight and confusion from overheating than an overly strong predatory drive.
Snakes biting their own tails is more common in fiction than in reality. Many spiritual traditions use the symbol of a snake biting its own tail. The symbol of the snake biting its own tail is called Ouroboros, from the Greek for "tail swallower".