What causes the tides? The simple answer is gravity - mainly the gravitational pull of the Moon. More precisely, the cause is the fact that its gravitational force decreases with distance. The Sun also has quite a large effect, but for all practical purposes we can ignore the effects of all the other heavenly bodies. Fortunately, the effects of gravity are linear - which means we can work out the effects of each body separately, and then add them up at the end. The force of the Moon on an element of ocean is given by Newton's famous law of gravitation which states that the force is proportional to the mass of the Moon and inversely proportional to the square of the distance between them. Therefore the Moon pulls the water upwards on the near side of the Earth, and downwards on the far side, but the downward force is weaker. The Earth also pulls the water downwards equally (and much more strongly) on both sides, so the net force is always downwards, and the oceans don't fall off.
So from this we might expect that the oceans would simply bulge up on the Moonward side of the Earth. But this is not the full story. As well as the Moon and Earth producing a force on the water, they also exert a force on each other. The Earth's pull on the Moon makes it fall toward the Earth, just as Newton's apple did. Yet, as we can see, it hasn't fallen on us yet. Why? The answer is that it's also moving sideways. As it travels sideways, which would take it away from the Earth, it also falls downwards, and the net movement keeps it at (approximately) the same distance.
In other words, it orbits about the Earth. But although we usually talk about the Moon orbiting the Earth, it also exerts a gravitational force on the Earth - which in turn orbits about the Moon. In fact, both orbit about their common centre of mass, which is within the Earth but not at its centre. This rotation causes an upward centrifugal force on the oceans, which is proportional to the rotational speed and the distance from the centre of mass. This force is greater on the far side than the near side.
Adding this to the Moon's gravitational forces produces equal upward forces on both sides of the Earth - and the familiar two-sided bulge of the oceans giving high tide twice daily.
Exactly the same reasoning applies to the effect of the Sun, although in this case the centre of mass is within the Sun, and the centrifugal force on the near side of the Earth is actually downward. It's no coincidence that in both cases the forces balance, because the centrifugal force is proportional to the orbital speed, which in turn is related to the mass and distance of the orbiting bodies.
The force of the Sun turns about to be about half that of the Moon. When Earth, Moon and Sun are in line, the forces add, giving the high spring tides; seven day later, they are at right angles, the forces partially cancel, and we get the low neap tides. Of course, the relative positions of Earth, Sun and Moon are changing all the time, so consecutive daily tides have different ranges, as do consecutive spring or neap tides. And the most important practical influence on the height of the tide is not included in this theory at all - the varying height of the ocean floor, which causes funnelling of the tidal flow, heaping the tides up in shallow water and causing even more complex effects where flows meet.
Look here for a more mathematical explanation, or return to the index.