"Some galaxies have no long spiral arms at all, but only numerous, short and non-symmetric arms, as in the Sculptor group galaxy NGC 7793. These arms are probably not density waves at all, but are short-lived star-forming regions that are sheared into spiral-like pieces by differential rotation of the galaxy. Such star-formation features last only as long as the bright, high-mass stars that dominate their light--about a hundred million years, less than a single rotation period of the galaxy. They apparently form when the disk is too stable to sustain a wave, or when there are no perturbations that could drive the formation of spiral arms."
Jerry Sellwood, who studies stellar group dynamics at Rutgers University, provided a helpful, broad overview of this area of research:
"The first part of your question was posed in 1850 by the Irish astronomer Lord Rosse after seeing the strikingly beautiful spiral pattern in Messier 51. While astronomers now generally agree that the spiral patterns in the majority of bright galaxies are density waves, experts still differ on how the arms are formed.
"A density wave is shorthand to describe the way stars in a galaxy are packed a little more closely together in the arms and spread more thinly in between the arms. The density variations travel round the galaxy, much like a sound wave through the air; therefore a spiral arm is not a simply a concentration of co-orbiting stars and gas.
"The problem of the origin of density waves is difficult because the billions of stars in a galaxy all exert gravitational forces on each other. Just as we can understand pressure in a gas without having to calculate the motions of individual molecules, we can treat a galaxy as a massive 'stellar fluid,' but the real difficulty stems from the long-range nature of the gravitational force. Computer simulations develop spirals spontaneously, confirming that gravitational dynamics is the important physical process, but it is hard to understand how this process works even inside the computer.
"Fortunately, nearly every one agrees that spiral patterns extract gravitational energy from the field of a galaxy. The inexorable force of gravity tries to pull the stars in a galaxy closer towards the center. The gravitational force is balanced by the orbital motion of a star (like a stone whirled on a string) which generally prevents it from settling any deeper on average into the galaxy. The spiral arms are a kind of catalyst that brakes the orbital motion of some stars, allowing them to sink slightly closer to the middle. Those with technical training will realize that if some stars lose angular momentum others must gain equally and, in fact, the stars that lose are near the inner end of the arms while those at the outer end gain. The gravitational stresses arising from the spiral density wave provide the torque.
"So, just as in capitalist economics, the stars near the center of a galaxy with little angular momentum have some taken away and given to those further out that were already angular momentum rich. Moreover, this process liberates energy: the stars that settle slightly closer are in the strong field of the inner galaxy, while the galaxy has a weaker hold on those that are pushed out.
"Hence it is energetically favorable for spiral patterns to develop because they provide the only possible torques to enable stars to become more tightly bound to the inner galaxy. Precisely what pulls on what to make the arms develop, the how part of your question, is much harder. There are several competing theories, all of which undoubtedly contain elements of truth, but none has gained wide acceptance.
"In the case of Messier 51, most experts agree that tides raised by the small companion galaxy are probably responsible for some of its exceptionally regular pattern, but too many galaxies display spiral arms for them all to be caused by interactions. Bars at the centers of galaxies are another idea that may drive spirals, but Messier 33 provides a clear counter-example to indicate that bars are not a universal mechanism either. I personally hope that the explanation will eventually be found in a recurrent dynamic instability (a flag flaps in a breeze because of a recurrent instability), but this idea still needs a lot more work.