Stars form from clouds of dust and gas called nebulae. Gravity causes the gas and dust to collapse into a dense protostar at the center. When the protostar becomes hot and dense enough, nuclear fusion occurs, releasing energy and causing the star to shine. A star's lifespan depends on its mass - lower mass stars last for billions of years, while higher mass stars only last millions of years before ending their lives in supernova explosions. Scientists classify stars based on their temperature and the elements they absorb, with classifications ranging from hottest O-type stars to coolest M-type stars.