Swarming is the way that honeybees reproduce in nature. If the queen runs out of space to lay eggs and the hive becomes too crowded with bees, the queen will leave with half of the colony to start a new colony somewhere else. The swarm will leave the hive in a swirling cloud of bees and land in a ball to rest on a nearby tree.
From there, 'scouts' will fly off in all directions looking for a good potential site for a new hive. If a bee finds a potential spot, she will fly back to the swarm and communicate the location by 'waggle dancing'. She will convince a few of her sisters to check out the site, and if they agree, they too will go back and waggle. Once enough of the bees agree that the site will work, the bees take of en masse and move into the new home, usually a nearby hollow tree.
The bees that are left behind raise a new queen to replace her, by feeding a regular female worker bee egg 'royal jelly' that they secrete from glands in their heads. This royal jelly turns on the reproductive system of the female egg and turns her into a queen. When the queen bee hatches, she will take a mating flight - she will leave the hive and mate (in mid flight) with about a dozen 'drones' (the term for male bees) who die in the process. She will store enough sperm, in a special organ called a spermethica, that she will be able to lay eggs for 3-4 years. She can actually choose the sex of the eggs that she lays - 90% of the bees in the hive are female and they do all the work!