Multiple theories exist that explain why cats knead. Kneading may have an origin going back to cats' wild ancestors who had to tread down grass or foliage to make a temporary nest in which to rest. Alternatively, the behavior may be a remnant of a newborn's kneading of the mother's teat to stimulate milk secretion. Kneading may also be a form of communication between owner and feline: because of the action’s maternal connection to the mother, the behavior may be a communication of affection towards the cat’s human companion. 
Kneading is often a precursor to sleeping.
Many cats purr while kneading. They also purr mostly when newborn, when feeding, or when trying to feed on their mother's teat. The common association between the two behaviors may indicate the origin of kneading as a remnant instinct. Some experts consider kneading to "stimulate" the cat and make it feel good, in the same manner as a human stretching.
The cat exerts firm downwards pressure with its paw, opening its toes to expose its claws, then closes its claws as it lifts its paw. The process takes place with alternate paws at intervals of one to two seconds. They may do this while sitting on their owner's lap, which may prove painful if the cat is large or strong or has sharp claws (as the claws tend to dig into one's lap). Though cats will sit happily on a hard surface, they will only knead a soft or pliant surface, although some cats will reflexively "march" on hard surfaces instead of kneading them.
A cat may appear irritated or surprised if it is disturbed while kneading.
In a garden where cats are to be found, sheltered areas can often reveal the "wild" results of kneading: round, cat-sized nests trodden into long grass. Domestic cats also make "nests" out of cardboard boxes and other such things. They do this also by kneading with their claws out, in a manner such as to scratch and soften some of the material. This action is different in manner, body language and intent from kneading when they are happy.
Cats knead soft objects such as teddy bears. Cats may adopt a blanket and use it like a security blanket. This will include lots of kneading, purring and suckling of the blanket. In some cases, cats have been observed to exhibit sexual movements, not unlike a dog "humping" a human leg, accompanying the kneading and suckling. Kittens who are taken away from their mothers before they are fully weaned may also develop a habit of kneading a human whom they have adopted as a maternal figure, and may also attempt suckling their ear, eye, nose, toe, hair, shirt, socks or fingers. Cats mainly do so as kittens, but sometimes the behavior continues into adult life.
Source and references
- Schwartz, Stefanie (June 2003). "Separation anxiety syndrome in dogs and cats". Journal of the American Veterinary Medical Association. 222 (11): 1526–32.
- Bradshaw, John (2016). "Sociality in cats: A comparative review. Journal of Veterinary Behavior". Journal of Veterinary Behavior: Clinical Applications and Research. 11: 113-124. – via Science Direct.
- Why Do Cats Knead?, www.petmd.com
- McPherson, F.J; Chenoweth, P.J (April 2012). "Mammalian sexual dimorphism". Animal Reproduction Science. 131 (3–4): 109–122.