A gravity assist involves three objects: A primary such as the sun, an orbiting body such as one of the sun’s planets, and the object to get the assist, such as a spaceprobe.
Let’s say you want to send a spaceprobe to Neptune. After getting free of the Earth’s gravity, your spaceprobe is now in an independent orbit around the sun, in approximately the same orbit as the Earth. To get to Neptune, you have to accellerate the spaceprobe enough so that it climbs up away from the sun out to Neptune. This would not only take lots of energy, but would involve coasting for decades as the probe slowly climbs up in an elongated elliptical path like a pop fly in baseball.
Fortunately, there’s a better way. You accellerate your spaceprobe just enough to reach Jupiter, which is faster and easier. Now Jupiter’s gravity pulls on the spaceprobe, pulling it toward the planet. If your probe doesn’t actually impact Jupiter, it whips past and out again. In the process, the spaceprobe gains speed in it’s path away from the sun at Jupiter’s expense: Jupiter is dragged back (by maybe the width of an atom) while the probe is flung forward. In fact, the probe can gain enough velocity to escape from the solar system altogether. If you time it right, you probe flys by the outer planets as it goes.