This may have an origin going back to their wild ancestors who would have had to tread down grass or foliage to make a temporary nest in which to rest, or possibly a remnant of the newborn kneading of the mother's teat to stimulate milk secretion: kneading is often a precursor to sleeping. Many cats also purr when kneading; they also do this mostly when newborn, while feeding or trying to feed on their mother's teat. The common association between the two behaviors may indicate the origin of purring as a remnant instinct.
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 in this action.
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 can sometimes adopt a blanket and use it like a security blanket. This will include lots of kneading, purring and suckling at the blanket. 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 suckling their ear, eye, nose or shirt. Cats will also do this to fuzzy stuffed animals, such as teddy bears. Cats mainly do this as kittens but sometimes it continues into adult life.