The earliest living creatures made babies by dividing themselves in half, so that one cell became two cells. But by about ?? years ago, some creatures with more than one cell began to develop specialized cells that could combine with the cells from another creature to make a new creature. These were the first eggs.
Reptiles began to lay eggs with hard shells made of calcium carbonate, a molecule combining carbon and calcium. Inside these shells, a baby reptile could grow safely until it was big enough to be born. Many animals, like snakes and birds, still lay hard eggs today.
About 200 million years ago, however, some reptiles evolved into mammals that kept their eggs inside them until the babies were big enough to be born. The earliest animals that kept their eggs inside them were the ancestors of the opossum.
Bibliography and further reading about animals: