Kittens knead at their mother’s belly when they feed; this helps to stimulate her milk flow.
When a kitten or cat kneads, they will push rhythmically in and out with alternating paws (kneading is also referred to as making biscuits or milk treading for this very reason). They often appear to be in a trance-like state, with eyes closed, sometimes drooling and purring. They seem to be enjoying the moment, and I view kneading as a sign of a contented cat.
In many cats, this kneading behaviour continues into adulthood. Cats can often be found kneading a soft or furry blanket, and some will even knead on humans. I have a cat who will also lie on his side and knead into thin air.