Earthquakes happen when the boundaries of the Earth's tectonic plates bump and slide past one another; sometimes, they get stuck on jagged edges and cause earthquakes once they are released. These earthquakes are always followed by aftershocks starting from the same epicenter.
The Earth's four main layers are the inner core, outer core, mantle and crust. The crust and the mantle make up a "skin" on the outside of the planet, but is not made of a single piece. The pieces of the mantle and crust are called tectonic plates with the outer edges of each of them called plate boundaries. The section where two plates meet and move is called a fault. As each of the plate boundaries get caught on each other, the rest of the tectonic plate keeps moving and energy begins to store at the point of friction.
When the energy overcomes the friction caused, all of the energy is released and radiates from the epicenter. These waves of energy are called seismic waves and ripple like water on a pond when a stone is dropped in. They often reach the surface of the planet where everything starts to shake. This is why cities or towns that are located near faults are more likely to feel earthquakes than those in the center of a tectonic plate.