As regards the formation of galaxies, it is assumed that initially the distribution of matter and energy was not even in the universe. These density differences caused differences in gravitational forces due to which the randomly distributed matter was drawn together forming the bases for development of galaxies.
A galaxy, whose diameter ranges from 80,000-150,000 light years, starts to form by the accumulation of hydrogen gas in the form of a very large cloud called nebula. The growing nebula eventually develops localised lumps of gas.
These lumps continue to grow into even denser gaseous bodies, giving rise to the formation of stars. The formation of stars in estimated to have taken place about 5 or 6 billion years ago. Galaxies spread over vast distances are measured in thousands of light years.
Light waves travel at 298,000 km. per second. A light year refers to the distance light travels in one year. Remember that galaxies are not stationary; rather they move away at or above the speed of light.