Earthquakes are a general nuisance and cause great mayhem. Scientists are still discussing how earthquakes are created but there is one generally accepted theory.
Most of the time we picture the Earth as a ball of solid material, but in fact it is more like a ball with liquid in it, a liquid consisting of molten rock called 'magma' (which is known as 'lava' when it bursts onto the surface through volcanoes). When the Earth formed it was like a great big ball of very hot gas, and due to gravity this ball of gas started to collect space debris and formed a kind of molten lump of rock. In space anything that is in a liquid state automatically forms a ball, and this is what happened to the Earth.
After a while the Earth cooled a bit and formed a shell of rock on the outside. The shell was only very thin, so when changes in pressure in the magma occurred the shell was broken and lava spilled out. Over a long period of time the earth cooled down even further, but in many places the shell continued to break up. Only places with relative stability could cool down, and in these places the shell of the Earth became relatively thick.
The places where the shell continued to break up formed thinner coverings of solid rock. This way 'islands' of solid rock formed with edges of much thinner rock; the edges are now called 'rifts' in the Earth's crust, and the islands 'plates'. These plates are a very good fit, but where they meet the plates collide against each other and create great upheavals on the surface. Some plates push together and create mountains - such as the Himalayas and the Andes - and in other places the continental plates move past one another along faults, or in regions where there is some strain present. Friction prevents motion of the blocks against one another, until the strain exceeds the frictional forces which hold the blocks immobile. When the blocks begin to move, water and ground rock along the fault serve form a lubricating mixture which facilitates movement along the fault plane, causing a large release of energy. This energy is absorbed as motion in the surrounding rock and forms the longitudinal and pressure waves which we feel as earthquakes.
An interesting fact is that San Fransisco is built on such a ridge, called the San Andreas Fault. This explains why there are so many earthquakes in this area.