Ballasts are arguably one of the more complex topics in lighting, because most of us see and understand the use of lamps or light bulbs while ballasts are working behind the scenes. You can learn more about them from our article on lighting ballasts (which includes information about the older and newer technologies along with the different starting methods and their pros and cons). But, in a nutshell, ballasts are used to run any sort of discharge lamp -- not only fluorescent lamps, but also high pressure sodium and low pressure sodium bulbs, mercury vapor bulbs, and metal halide bulbs.
These ballasts -- whether fluorescent ballasts or HID ballasts -- are used to provide the initial voltage to start a bulb and to limit the current passing through the bulb to prevent the lamp from breaking. The ballast's function uses some energy of its own, and this is called the ballast's loss factor, and should be considered along with the wattage of the lamps to know the total energy use of the system when the lights are on.
Importantly, you should realize that a ballast has specifications that need to be matched with the bulb(s) it will run. These specs are provided on the ballast itself, and we provide this kind of information on our ballast product pages when you need to make a purchase. (We're also available by phone to help you choose the right ballast.) There are even ballasts designed for specific applications, like Fulham IceHorse ballasts for refrigeration settings.
We thought we'd wrap up by sharing this video, which actually gives you a glimpse inside an old magnetic ballast and shares several details on the topic as well.