The moon's dominant pull and gravitational gradient
Tides arise from the moon's gravity pulling more strongly on Earth's near side than its far side. Although the sun is vastly more massive, it is also much farther away, so the gradient of its pull across Earth's diameter is weaker. The moon wins by a factor of about 2 to 1. As Earth rotates beneath the moon's gravity well, ocean water bulges toward and away from the moon, creating two tidal peaks per day. The gradient effect explains why the tidal force depends on the moon's distance cubed, not just its mass; bring the moon twice as close and the tidal pull increases by a factor of eight.
Sun-moon alignment and tidal range
Although the moon dominates tides, the sun reinforces or opposes lunar tides depending on alignment. When the sun and moon align (at new moon), both pull in the same direction, creating exceptionally high spring tides and low neap troughs. When the sun and moon are at right angles (at first and third quarter), their effects partially cancel, yielding smaller neap tides. This monthly cycle of tidal range has been exploited by coastal ecosystems and human navigation for millennia. Tidal friction also slowly dissipates orbital energy, moving the moon away from Earth at about 3.8 centimeters per year and gradually lengthening the day by roughly 1.7 milliseconds per century.