Before delving into an answer, it is important to note that the spiral arms of galaxies are not fixed, solid objects; rather, they are patterns of bright stars and gas clouds within the overall form of the galaxy. The space between the spiral arms is not empty, and stars can move in and out of the arms as they orbit through the galaxy.
Ray Carlberg in the astronomy department at the University of Toronto sent in this description of what scientists know about the nature of spiral galaxies:
"The basic physics of why galaxies have spirals is known, but the details remain controversial, sometimes intensely so. Spirals exist only among flattened or 'disk' galaxies. These galaxies are differentially rotating--that is, the time to complete a full rotation increases with distance from the center. Differential rotation causes any disturbance in the disk to wind up into a spiral form. The trouble with this simple explanation is that the differential rotation would cause spiral features to wind up too quickly, so galaxies would not look like spirals for any appreciable length of time.
"The second important piece of physics for understanding spiral structure is that the stars and gas in the disk of the galaxy exert an appreciable gravitational force. That force helps maintain the spiral form against the tendency to wind up. Almost everyone agrees on this basic physics.
"So, why do disk galaxies often have spiral shapes? There is observational evidence that nearby companion galaxies or an asymmetric, bar-shaped concentration of mass can drive a spiral wave in the disk of the galaxy. Disks that lack such forcing features are the tricky ones to explain. One explanation centers on the fact that gravitational systems act to increase their central binding energy. Spiral arms remove angular momentum from the center of the galaxy, allowing it to achieve a state of higher binding energy. There are two main versions of the theory of spiraling: one in which the waves are steady and long-lived, the other in which spirals are transient features that come and go. The natural, but not very easy, test is to observe spiral galaxies for a few hundred million years and see what happens."
Debra M. Elmegreen, Maria Mitchell Professor of Astronomy at Vassar College, and Bruce G. Elmegreen, staff scientist at the IBM T.J. Watson Research Center, have extensively studied this question. Here is their response:
"Most spiral arms in galaxies are density waves, which are compression waves (like sound) that travel through the disk and cause a piling-up of stars and gas at the crest. The wave is temporarily sustained by the force of its own gravity, but it eventually wraps up or gets absorbed at orbital resonances, places where random stellar oscillations have the same period as the local wave.
"In some galaxies, a large central bulge can prevent the wave from reaching a resonance; the wave then reflects off the bulge, giving rise to a giant standing spiral wave with a uniform rotation rate and a lifetime of perhaps 5 to 10 disk rotations (roughly one to two billion years). In all cases, the stars and gas rotate around the galaxy's center faster than the wave in the inner parts of the disk, and slower than the wave in the outer parts. This differential rotation forces gas to enter the wave at a high speed in the inner regions, causing it to shock and form long, thin dust lanes in each spiral arm. Some density-wave galaxies, like M81, have highly symmetric spiral arms; others, like M101, have several arms and less overall symmetry. The difference between these two cases is related to the symmetry of the perturbation that formed the arms in the first place, and to the relative importance of the standing wave pattern, which tends to be symmetric.
"Density waves have many possible origins. A large central bar, such as is seen in NGC 1300, may drive a two-arm density wave for a relatively long time, eventually causing the gas in the outer disk to move outward and wrap into a giant ring at the edge of the galaxy's disk. A companion galaxy can also generate a two-arm spiral by tidal forces. Such tidal arms probably last only for several rotations before they either wrap up and disappear or initiate a longer-lived standing wave. The Whirlpool galaxy, M51, has companion-triggered spirals. Galaxies that appear in visible light to have neither bars nor companions can still have spiral waves. These galaxies may have hidden weak bars or small companions that trigger the spirals, or they may be excited entirely by small asymmetries and perturbations within their disks.