Scientists have been debating this question for a long time. Some believed that snakes evolved on land, and that their ancestors were small, burrowing lizards. And others believed that snakes evolved from the mosasaurs, giant swimming lizards that lived 144 to 65 million years ago.
Unfortunately, it's difficult to analyze the genes of the extinct mosasaurs. So instead, scientists at Penn State analyzed the genes of their closest living relatives, the monitor lizards. In fact, these scientists examined genetic material representing all nineteen living lizard families, and seventeen of the twenty-five families of living snakes.
They analyzed the differences in genetic structure that inevitably result from the slight mutations that develop over time. This enabled them to map a genetic family tree. They discovered that snakes aren't closely related to monitor lizards. Now, because the mosasaurs-- the monitor lizards' ancestors--were the only marine lizards around when snakes evolved, snakes must have evolved from lizards living on land.
There's a strong correlation between the burrowing lifestyle and very small limbs or the complete loss of limbs. Some burrowing lizards have reduced limbs and some have lost one or both pairs. After all, you could fit into much smaller openings if you didn't need a pelvis or shoulders to support your limbs.