Ferns have two distinct parts to their life-cycle.
The familiar fronded plants produce spores that disperse in the wind. If the spores land somewhere suitable, they grow into a gametophyte. Gametophytes are tiny - a few millimetres long - and are easily overlooked. It is the gametophytes that produce the gametes, eggs and sperm. The eggs are held within the gametophyte. The sperm need water in which to swim through to reach an egg. On fertilisation, a sporophyte - the familiar fern plants - grow out of the gametophyte, and the cycle continues.
All land plants have a two part life-cycle, but ferns are unique in that both the sporophyte and gametophyte phases are free-living.
Wikipedia's Alternation of Generations.