Most squamates (lizards and snakes) living today are egg layers, but several species birth live young (viviparity) like mammals. Reptilian viviparity evolved to protect offspring in cold climates, separately doing so in squamates over 100 times.
Viviparity makes sense where temperatures dip so low that egg-encased embryos would develop slowly or not at all. A female carrying her young can regulate temperature by moving to a warmer location as necessary, thus enabling embryos to mature faster and at less risk.
Some tropical lizards are viviparous. These lizards adopted live birth when they lived at high elevations, where it got too cold to risk laying eggs. They then came down to enjoy the balmy weather. Their flexibility in being able to mate with mountainous relatives made them more fit than the egg layers confined to the lowlands, with whom the once-mountaineers will not interbreed.
Lizards in temperature regions came from those that evolved in the mountains, then ventured down to the tropics before migrating north.
Live birth is also related to body size. Small squamates must lay eggs, as their bodies cannot support viviparity.
Marine reptiles that live in the sea – ichthyosaurs and plesiosaurs – also evolved viviparity out of adaptive necessity. However intricate the adaptations involved in bearing live young, the basic mechanism is straightforward: viviparity evolves from oviparity via egg retention.
Viviparity independently arose at least 115 times in various lizards and snakes. The squamate genome affords rapid adaptation to the birthing mode most efficacious for lifestyle.