The first form of reproduction began about four billion years ago, when first RNA molecules and then DNA molecules began to make new copies of themselves by letting amino acids hook on to the parent molecule and then splitting them off. All reproduction since then has been the same thing - DNA molecules making more of themselves - only the DNA molecules have evolved more and more complicated ways to protect themselves and help the process along.
The earliest living cells were wrappers around DNA molecules. About 3.8 billion years ago, they began to make new cells by splitting in two, using a process called mitosis. Your own cells still use mitosis all the time to make new cells, like if you exercise and build more muscle.
About 1.4 billion years ago, more complicated eukaryote cells evolved that could make new cells using a different process called meiosis. Meiosis took a mother and a father cell, and combined their DNA and then divided it again, so that the new cell had some DNA from its mother and some DNA from its father. Meiosis was a huge advantage for cells that used it, because mixing up the DNA let cells evolve faster to cope with changing conditions.
Frog eggs in the water
When the first multicellular organisms like hydras evolved around 600 million years ago, they had to reproduce two different ways. If they used mitosis to divide cells, that made them grow bigger. But to make a baby, they used meiosis to make a new small independent creature. These first creatures just released lots of egg cells and sperm cells into the ocean and usually some of them would happen to meet up and combine to make a baby. Early animals were both dad and mom - one hydra, or one earthworm, could make both eggs and sperm.
This same system continued to work pretty well for fish, and then for frogs. Fish and frogs, though, were either moms or dads - they could make either eggs or sperm, but not both. Even though by 375 million years ago frogs lived partly on land, they had to come back to the water to lay their eggs.
But not long after that, about 310 million years ago, reptiles figured out how to lay their eggs on land, so they didn't have to go back to the water. These eggs had hard shells made of calcium, to keep water around the baby even when it was on land. To get the sperm to the egg, reptiles began to have sex. Birds, which evolved from reptiles, also lay eggs, and also have sex.
A cow giving birth
But then some reptiles and most mammals began to keep their eggs, and their babies, inside their own bodies, where they would be really safe until they were born. That happened about 200 million years ago. Instead of being born inside eggs, the babies grew inside their mother's bodies, and then were born alive, like you.