When plants like moss first began to grow outside the water, about 540 million years ago, they needed a way to reproduce themselves that didn’t depend on water so much. Some of these plants evolved to be able to produce spores.
To make spores, plants like moss begin by dividing some cells using meiosis to produce haploid sperm and egg cells. These use mitosis to grow into photosynthesizing plants: the soft plant you recognize as moss is the haploid plants. Then these fuse together into one diploid plant – that’s the thin stalks that stand up above the moss – that soon make new haploid egg and sperm cells. The diploid plant doesn’t photosynthesize, and depends on the haploid plant for food.
When more complex plants like ferns evolved, they also used spores to reproduce. Spores don’t require a lot of energy to produce. But spores need to land on wet dirt, or they’ll die. In order for plants to move away from the edge of streams and ponds, they had to evolve a way of reproducing that didn’t involve water – the seed.
Bibliography and further reading about spores and plant reproduction: