According to NASA, solar eclipses occur when the moon blocks the view of the sun from Earth, and a lunar eclipse occurs when the Earth's shadow covers the surface of the moon. The perfect alignment necessary for a full eclipse is relatively rare, with partial eclipses happening much more frequently.
Eclipses happen only at certain points in the lunar cycle. When the moon is full, it is directly opposite the sun from the Earth, and only then can the Earth's shadow line up properly to block the sun's light. Similarly, solar eclipses only occur during a new moon, when the moon is lined up on the same side of Earth as the sun. Even so, the particular alignment can vary with the orbital paths of the Earth and moon, so simply being in the right phase does not guarantee one of these celestial events. Only when the sun, Earth and moon are aligned exactly in what is called the ecliptic plane can an eclipse occur.
In any given year, there are between two and five lunar eclipses that at least partially obscure the moon's surface. Solar eclipses are rarer, occurring only once every 18 months, but since they may only affect small parts of the Earth at any time, any given spot may go for hundreds of years between eclipses.