How galaxy simulations work, explained with what you see
A galaxy simulation turns stars into particles, adds up the gravity on each one and steps time forward, with shortcuts that decide what you see. Tidal tails come from differences in gravity across a galaxy; real galaxies merge because dark matter drains their orbits; and gas and new stars are always approximated. Explained with frames from a live simulation, by the maker of one.

I make Everdust, whose galaxy simulations appear on this page, so read the last part with that in mind. The rest is the physics that every galaxy simulator, ours included, is built on.
A galaxy simulation represents a galaxy as a cloud of particles, works out the gravitational pull on every particle, nudges each one forward a small step in time, and repeats that thousands of times. Everything you see in a galaxy collision, the long tails, the bridges of stars and the final merger, comes out of those small steps. What differs between a phone app and a research supercomputer is how many particles there are, how the pulls are added up and which physics is left out.
What is a galaxy simulation actually computing?
Newton's law of gravity: every mass pulls on every other mass, more strongly the closer they are. Give a computer the position, velocity and mass of each particle, and it can work out the acceleration on each one, move them all a little, and do it again.
A real galaxy has hundreds of billions of stars, far too many to follow one by one. So a simulation particle usually stands for a whole group of stars, or for a lump of dark matter or gas. This matters for what you see: a simulated galaxy is a fair statistical picture of the real one, not a star-by-star copy.
Why can't you just add up every pull?
You can, and it's exact, but it's slow. With N particles there are N × (N − 1) / 2 pairs to compute on every step, so doubling the particles makes each step four times the work. A million particles means about half a trillion pairs, every step.
In 1986 Josh Barnes and Piet Hut published the trick most codes still build on: group distant particles into the cells of a tree, and treat a far-away cell as a single mass at its center of mass. A far cluster of stars pulls on you almost exactly as one big star would. The work then grows roughly as N log N instead of N², which is what made simulations of millions of particles practical. Large cosmological codes such as GADGET add a grid for the longest-range forces on top of the tree.
Why are the stars "softened"?
If two particles pass very close, the pull between them shoots toward infinity and one gets flung out at absurd speed. Real stars almost never come that close, because the gaps between them are enormous (that's why stars almost never collide when galaxies do). And since each particle stands for many stars, a sharp kick from one close neighbor wouldn't be realistic anyway.
So codes soften gravity: inside a small distance, called the softening length, the pull stops growing and fades smoothly instead. Choosing that length is a trade-off. Too small and you get spurious kicks; too large and the galaxy's inner structure is blurred.
How does time move forward?
Most galaxy codes use a leapfrog integrator. Each step gives every particle half a kick of velocity, moves it with that velocity, then gives the second half kick. It's simple, but it has a valuable property: over millions of steps an orbit doesn't slowly spiral in or out the way it would with a careless method. That's why a simulated disk can turn for many rotations and still look like a disk.
The shortcut that explained tidal tails
The first galaxy collision "simulation" ran in 1941, before electronic computers. Erik Holmberg built two model galaxies from light bulbs, with each bulb's brightness standing in for its mass, because light fades with distance the same way gravity does. He measured the light falling on each bulb with a photocell, moved the bulbs, and repeated. His model galaxies grew tidal features.
In 1972 Alar and Juri Toomre made a cleaner version on a computer. They kept only the two galaxy centers as masses and let each star feel just those two, not every other star. It's a big shortcut, called the restricted three-body method, but it reproduced the long tails and bridges of real interacting pairs such as the Antennae and the Mice so well that it convinced astronomers those shapes are made by tides.
Here's why. The near side of a galaxy is pulled toward the passing neighbor more strongly than its center is, and the far side less. The galaxy gets stretched: stars on the near side are drawn out into a bridge toward the neighbor, and stars on the far side are left behind as a tail. The Toomres also found that a disk spinning the same way as the encounter (prograde) throws out long tails, while one spinning against it barely changes. That's one reason the two members of a colliding pair often look so different.
Why real galaxies merge: dark matter and dynamical friction
In the Toomres' setup, the two centers are point masses on a fixed orbit. They swing past, come back and swing past again, but they can't merge, because nothing takes away their orbital energy.
Real galaxies sit inside much larger halos of dark matter. When two halos overlap, each galaxy plows through the other's dark matter and pulls it into a wake behind itself. That wake's gravity drags the galaxy back. Subrahmanyan Chandrasekhar worked out this effect, dynamical friction, in 1943. In 1988 Josh Barnes ran encounters with the bulges, disks and halos all modeled as particles, and the galaxies made strong tidal tails and then merged quickly. Without the halos, that doesn't happen on a realistic timescale.
What's left after a merger of two similar spirals is usually a rounder, smoother galaxy, much closer to an elliptical than to either spiral. This is also the future that may await the Milky Way and Andromeda, though whether they merge at all is now about a coin toss.
Gas, new stars and what every simulation approximates
Stars barely interact, but gas clouds do: they collide, heat up, lose energy and sink. In simulations of merging galaxies, such as those by Chris Mihos and Lars Hernquist in 1996, tides drive gas into the centers, where it can set off a burst of star formation.
No simulation can follow a single star being born inside a galaxy-sized run, so star formation, exploding stars and black hole growth are added as "subgrid" recipes: rules of thumb that turn dense, cold gas into new stars at a chosen rate. The big research simulations, such as EAGLE and IllustrisTNG, are largely defined by these recipes, and they're tested by checking whether the galaxies they make look like the ones telescopes see.
So whenever a simulation shows bright knots of new stars, it's worth asking what recipe made them.
What you're seeing in Everdust
Here's how the simulations on this site and in the app map onto all of the above.
- The galaxy collision in your browser (try it) is the Toomres' method, running on your graphics chip. Two softened centers orbit each other, and every star is pulled by both, stepped forward with a leapfrog integrator. Each disk starts with its stars on circular orbits. The tails and bridges are real results of the physics. With no dark matter halos, the centers keep swinging rather than settling into one galaxy.
- The app's merger gives each galaxy a dark matter halo and lets the centers feel dynamical friction, so they really sink together and merge, as in the frames on this page. Its gas is "sticky": gas particles that crowd together lose their speed relative to each other, roughly as colliding clouds do, and gas squeezed well past its starting density lights up as pink knots of new stars. That's a recipe in the spirit of the research codes, not a full model of gas.
- What's left out: the stars don't pull on each other, only the galaxy centers and halos do the pulling, there are no exploding stars or black holes feeding, and time is enormously compressed. A first pass that takes hundreds of millions of years plays out in seconds.
- The pink glow where the tides are strongest is a visual cue tied to tidal strength in the browser version. When music is playing, the beat can also set it off, so it's not a measurement.
The upshot: the shapes you see, the tails, bridges and fans of stars, come from the same physics astronomers used to explain real colliding galaxies. The fine detail of gas and new stars is the part every simulation, big or small, approximates.
Try it
- Galaxy collision simulator, free in your browser with nothing to install.
- Photo to particles: wind your own photo into a spiral with its Galaxy effect, free in your browser. It's an effect, not a simulation: no gravity is computed.
- Everdust on the App Store for iPhone, iPad and Apple Vision Pro, on Google Play for Android and on the Meta Horizon Store for Meta Quest, free to download with no ads. In the app, the galaxies chapter of The Story of Everything (free in full) narrates a merger while it runs.
- For other galaxy simulators, including Universe Sandbox and SpaceEngine, see our honest guide to galaxy and black hole simulators.
Questions people ask
How do galaxy simulations work? They represent a galaxy as particles, each standing for many stars or a lump of dark matter or gas, compute the gravity on every particle, and step time forward in small increments. Tree methods speed up the force calculation, softening avoids unrealistic close kicks, and gas and star formation are added as approximate recipes.
Why do colliding galaxies form tidal tails? Gravity weakens with distance, so the side of a galaxy nearer a passing neighbor is pulled harder than its center and the far side is pulled less. The galaxy is stretched into a bridge on the near side and a tail on the far side. Alar and Juri Toomre showed this with computer simulations in 1972.
Why do galaxies merge instead of passing through each other? Their dark matter halos. As a galaxy moves through the other's halo, it gathers a wake of dark matter behind it whose gravity slows it down, an effect called dynamical friction. The galaxies lose orbital energy, fall back together and merge.
Do stars collide when galaxies collide? Almost never. The distances between stars are so large compared with the stars themselves that the two galaxies pass through each other star by star. Gravity, not collisions, reshapes them.
Is there a free galaxy collision simulator online? Yes. Everdust's galaxy collision simulator runs free in a web browser, using the same method the Toomres used. The Everdust app adds a version with dark matter halos, where the galaxies merge.
Sources
- Holmberg, E., On the Clustering Tendencies among the Nebulae. II., The Astrophysical Journal 94, 385 (1941).
- Chandrasekhar, S., Dynamical Friction. I. General Considerations: the Coefficient of Dynamical Friction, The Astrophysical Journal 97, 255 (1943).
- Toomre, A. and Toomre, J., Galactic Bridges and Tails, The Astrophysical Journal 178, 623 (1972).
- Barnes, J. and Hut, P., A hierarchical O(N log N) force-calculation algorithm, Nature 324, 446 (1986).
- Barnes, J. E., Encounters of disk/halo galaxies, The Astrophysical Journal 331, 699 (1988).
- Mihos, J. C. and Hernquist, L., Gasdynamics and Starbursts in Major Mergers, The Astrophysical Journal 464, 641 (1996).
- Springel, V., The cosmological simulation code GADGET-2, Monthly Notices of the Royal Astronomical Society 364, 1105 (2005).
- Schaye, J. et al., The EAGLE project, Monthly Notices of the Royal Astronomical Society 446, 521 (2015).
- Nelson, D. et al., The IllustrisTNG simulations: public data release, Computational Astrophysics and Cosmology 6, 2 (2019).
- ESA/Hubble, The Mice (NGC 4676), Hubble's 2002 image of a colliding pair with long tidal tails.