Gravity is the attractive force between any two objects with mass, and decreases with the square of the distance between those objects
Gravity is an attraction between two objects based on how much mass they have. Recent experiments at the CERN particle collider revealed some details on how an object gets mass, but it’s enough to say that mass just describes how much stuff there is to something. Heavier things have more mass, and denser things have more mass per unit volume.
Gravity as a force depends on mass, which is why it’s harder to pick up a bowling ball than a balloon—the Earth is pulling down harder on the heavier object. The mass of the Earth matters in calculating the force, too—that’s why you’d weigh less on the Moon (about 83% less than your Earth weight), because its gravitational force would not pull you down as hard as the Earth does.
The moon pulls strongest on the near side of the Earth, so water here is affected most
So the force of gravity decreases if the masses involved decrease, but it also depends on how far away these objects are. This is why the Sun, which has much, much more mass than the Earth, doesn’t pull us all off into space with its gravity—it has a lot more mass, but it’s a lot farther away. It turns out the gravitational force changes as the square of the distance—physicists call this an “inverse square law”, meaning a twice greater distance decreases the force by a factor of 4.
That distance squared part can have a big effect. For example, the diameter of the Earth is just under 8000 miles (12,700 km). This means that any force pulling on the Earth will be a bit weaker on the far side. In the case of the moon pulling on the Earth, there is about a 4% weaker pull on the far side of the Earth compared to the near side.
As a result there is a little bit of stretching that occurs along the direction of the gravitational force—things closer to the moon get pulled toward it a bit harder than things near the middle of the Earth, which get pulled a bit harder than things on the far side. This force from the moon will be felt by all things on the Earth—including people—but it’s really only noticeable on something like ocean water. One the one hand there is quite a lot of water to be pulled on, and as a liquid it’s also able to be moved easily. The gravitational pull from the moon also stretches the solid material that makes up the Earth as well, but it’s way too small to be noticed easily.
Since the moon revolves around the Earth in just over one day, there are often two high tides and two low tides in a location
The Earth is rotating underneath the moon, and so the direction of this stretching is changing all the time. If you sit and watch the ocean at one beach you’ll probably notice two high tide points and two low tide points over the day. The high tide occurs once when the moon is more or less overhead and again when it’s more or less underfoot (on the other side of the Earth), and the two low tides happen when it’s halfway between these two points as the Earth rotates. In fact the tides occur on just a bit longer than 24 hour schedule because the moon is revolving around the Earth as well so it jumps out ahead of you just a bit as your beach rotates around underneath.
The sun also has a tidal effect, but it’s not as strong due to its larger distance
The sun also has this tidal effect on the Earth’s water, but it’s a little less than half as strong. This goes back to the inverse square dependence of gravity: even though the Sun is much more massive than the moon, the moon is a whole lot closer. If the sun lines up with the moon one side of the Earth, though, there will be just a bit bigger tide—these are called spring tides (named for the “spring upwards” in water level, not that it occurs during any particular season), and when the sun is working against the moon the tide can be at its minimum, called a neap tide.
Bonus physics—Tidal locking
This forces that cause tides on the Earth also have an effect on the moon. In this case tidal forces have over time caused the moon to become tidally locked to the Earth—this means that the moon rotates about its own axis at the exact same rate as it revolves around the Earth. The result of this is that the same side of the moon always faces towards us on Earth. This happens because of tidal forces—if the moon was rotating faster than it revolved around us then the Earth’s tidal forces would pull on the resulting bulge a little bit, slowing the rotation speed. This is why you can always see the same crater pattern on the moon—it’s the same side facing us all the time.
Bonus physics—Black hole tidal forces
Tidal forces are one problem with sending things into black holes—the gravity near one is so great that the tidal forces are enough to stretch out anything that gets too close. Just like the moon pulls more on one side of the Earth than the other, an incredibly strong source of gravity would pull much more on one end of, for example, a rope than the other, resulting in a stretching and eventually breaking of the rope. This process is somewhat comically known as “spaghettification”, and would most likely happen to any satellite or ship we may try to send inside a black hole.