A galaxy is a huge mass of stars,nebulae, and interstellar dust and gases .Nebulae are clouds of dust and gases (mainly hydrogen and ionized hydrogen) that float in space .Often, the force of gravity pulls the particles of gas and dust closer into a swirling mass .If the mass is heavy enough,the spinning clouds will start to glow .This is a protostar, or first stage before a star is born

Stars are self-luminous bodies of hot and glowing gas(hydrogen) born inside the nebulae itself .Our Sun is a small star .Massive stars may have a mass of at least three times that of a Sun and some stars are massive as 50 times of Sun exist .Stars produce energy by nuclear fusion at the core .After millions or billions of years,when hydrogen starts running out,the core contracts while the outer portion continues expanding .The star is now called a red giant .The amount of mass a star has determines the rest of its life cycle .The core of low mass stars collapse,expelling the outer layers,which form a nebula .The core remains as a white dwarf and eventually cools to become a black dwarf .
A massive star will undergo a supernova explosion .If the remnants of the explosion is 1.4-3 times as massive as the Sun ,it will become a neutron star .After the explosion, a star with a core three times the Sun,will be swallowed by its own gravity .It now becomes a black hole which can readily attract any matter or energy that comes near it .