There are many depictions of Vishnu resting on a Snake. But why is it that the snake is sometimes depicted as 3-headed, 5-headed or 7-headed?
What is the meaning or importance of snakes in Hinduism?
Snakes are very important in Hinduism. There are many reasons for this; snakes shed their skin, and grow it back later. This represents "rebirth", while also representing death and mortality. Not just that - snakes cannot be tamed; hence, they represent freedom. Another reason is given here:
All nagas are considered the offspring of the Rishi or sage, Kasyapa, the son of Marichi. Kashyapa is said to have had by his twelve wives, other diverse progeny including reptiles, birds, and all sorts of living beings. They are denizens of the netherworld city called Bhogavati. It is believed that ant-hills mark its entrance.
Also, the same source tells:
The Indian mahasiddha, Nagarjuna, received his illuminating insights and tantric empowerment with the help of the nagas in the lake beside which he meditated.
According to the Hindu Scriptures, Naga live in the Netherworld called Naga-Loka or Patala-Loka with unimaginable richness. When the Naga were over populated on the earth, Brahma, the Creator, banished them to the underworld. Naga are the children of Kashyap Rishi who married Brahma 13 daughters. Their mother’s name is Kudra. Kashyap is also the father of gods, demons and animals.
Snakes are Lord Shiva’s garland, anklets and armlets. Hindu gods like Bhairav and Mahakala are protected and decorated by snakes. Thousand-headed Naga called Ananta protects Goddess Kali. Like Lord Vishnu, many gods rest on Naga or are protected by Naga. Naga guard Hindu temples and shrines. Naga are depicted on the doors, windows and the walls of the temples. Naga are also the seat of the deity.
Tantra and Yoga, which are the esoteric practices in Hinduism, philosophize about serpent power inside human body. This serpent called Kundalini, depicted as a coiled snake, would be evoked by mysterious yogic practices or tantric rituals. When this serpent power is awakened ignoramus humans are said to be liberated from worldly vices. Literal meaning of Kundalini is coiled Naga.
The multiple heads on the snake is symbolic; it is used to denote protection. This number may vary, for the reason I mention below. As Wikipedia says,
Shesha (Adisesha, Sheshnaga, or the 1000 headed snake) upholds the world on his many heads and is said to be used by Lord Vishnu to rest.
Why does the snake have multiple heads? The Puranas tell that Shesha holds all the planets of the Universe (we now know it is in the solar system) on his hoods. A possibly non-spiritual explanation for the number of heads is said here:
The seven-headed Naga serpents depicted as statues on Cambodian temples such as Angkor Wat possibly represent the seven races within the Naga society.
Snakes are a symbol of alertness. They signify the raising of awareness as a result of meditation. I assume the number used (3, 5 or 7) is just an artistic rendition.
If you look at the mythological pictures, you will find Mahavir sitting with a five headed cobra behind him. Or Lord Vishnu is sitting in meditation and there is a cobra behind him. Even in the pictures of Rishis, you will find a cobra with its hood open at the back. Have you seen such pictures? It is a very subtle thing!
See, when you are sitting in meditation, what is happening? Your consciousness is getting alert, opened and awakened, as though in your back ground there is a thousand headed cobra. Cobra signifies alertness.
How many of you feel a lot of alertness in the back of your head during meditation? A sort of wakefulness!
So the cobra is a symbol of the energy that raises and opens up; energy which is alert and at the same time restfulness.
It is not that there was really a cobra at the back of their head, it is a symbol of wakefulness in the deep state of rest, and that is meditation – totally restful, wanting nothing, doing nothing, being nothing and being open, like the hood of a cobra; alert without any effort.
There are two types of descriptions for this. In one they talk about a Cobra, and in another they talk about a flower; it is like a thousand-petaled lotus, blossoming on the top of the head; on the crown chakra.
So some describe it as a flower, very delicate, and some describe it as a cobra which means alert. Both fit very well.
From a talk by Sri Sri Ravi Shankar: http://celebrating-silence-of-life.blogspot.in/2012/11/symbolism-of-five-headed-cobra.html