The moon and the sun both exert gravitational force on the earth’s surface. Since water is light and easy to pull on, and we see the results of the sun’s and the moon’s gravity on ocean water in the form of tides.
As the earth rotates once every 24 hours, any place on earth will be closest to the moon and farthest away from the moon roughly every 12 hours (actually 12 hours and 22.5 minutes, since the moon orbits in the same direction that the earth spins and the earth has to catch up a bit). The part of the earth closest to the moon will have the highest tide, since water the ocean water is attracted to the moon, but the place closest away will also have a high tide. This is because the ocean is like a ball – if you squeeze it in the middle, the part toward and away from where you squeeze bulge out. So if the moon pulls the nearest water toward it, the furthest water also bulges out, while the 2 sides receive low tides.
This effect causes most places on the earth to have a high tide every 12+ hours, with a low tide in between.
The moon also orbits once around the earth every 28 days. At 2 times in the month, the moon will line up with the earth and the sun at the same time. When they line up, the gravity of the moon and the sun combine to form the highest tides of the month, called spring tides, every 2 weeks. In the weeks between, the moon and the sun cancel each other’s gravity out and produce the lowest tides, called neap tides.