Stars are formed in nebulae, interstellar clouds of dust and gas (mostly hydrogen). These stellar nurseries are abundant in the arms of spiral galaxies.
In these stellar nurseries, dense parts of these clouds undergo gravitational collapse and compress to form a rotating gas globule.
The globule is cooled by emitting radio waves and infrared radiation. It is compressed by gravitational forces and also by shock waves of pressure from supernova or the hot gas released from nearby bright stars. These forces cause the roughly-spherical globule to collapse and rotate. The process of collapse takes from between 10,000 to 1,000,000 years.
A Central Core and a Protoplanetary Disk:
As the collapse proceeds, the temperature and pressure within the globule increases, as the atoms are in closer proximity. Also, the globule rotates faster and faster. This spinning action causes an increase in centrifugal forces (a radial force on spinning objects) that causes the globule to have a central core and a surrounding flattened disk of dust (called a protoplanetary disk or accretion disk). The central core becomes the star; the protoplanetary disk may eventually coalesce into orbiting planets, asteroids, etc.
The contracting cloud heats up due to friction and forms a glowing protostar; this stage lasts for roughly 50 million years. If there is enough material in the protostar, the gravitational collapse and the heating continue.
If there is not enough material in the protostar, one possible outcome is a brown dwarf (a large, not-very-luminous celestial body having a mass between 1028 kg and 84 x 1028 kg).
A Newborn Star:
When a temperature of about 27,000,000°F is reached, nuclear fusion begins. This is the nuclear reaction in which hydrogen atoms are converted to helium atoms plus energy. This energy (radiation) production prevents further contraction of the star.
Young stars emit jets of intense radiation that heat the surrounding matter to the point at which it glows brightly. These narrowly-focused jets can be trillions of miles long and can travel at 500,000 miles per hour. These jets may be focused by the star's magnetic field.
The protostar is now a stable main sequence star which will remain in this state for about 10 billion years. After that, the hydrogen fuel is depleted and the star begins to die.
The most massive stars have the shortest lives. Stars that are 25 to 50 times that of the Sun live for only a few million years. Stars like our Sun live for about 10 billion years. Stars less massive than the Sun have even longer life spans.
The energy the star gains by fusing these atoms keeps it from collapsing. If a star is massive enough, it will fuse heavier and heavier atoms -- hydrogen to heluim, heluim to carbon, carbon to ... until ... elements are fused into iron. Fusing iron to form heavier elements actually requires energy, so the star would not gain anything by continuing fusion of iron atoms. Most of the star's life is spent fusing hydrogen into helium. Our sun has been doing this for some five billion years, and is expected to continue doing it for another five billion or so years. This hydrogen burning starts from the very center of the star, and moves its way out, leaving a core of helium behind.
Low Mass Stars
If the star is small enough (much less than the mass of our Sun), it never gets beyond hydrogen burning. This is because its central temperature never gets high enough to start fusing helium into carbon. Once such a star has used up most of its hydrogen, it will begin to cool and collapse into a "brown dwarf". Intermediate Mass Stars
Stars with masses close to that of our Sun (up to about five times the mass of our Sun) will experience helium-to-carbon burning in their cores. Outside the helium core, hydrogen will continue burning into helium.
At this point, the outer layers of the star will expand to...