The Earth spins on its axis due to the conservation of angular momentum. During its formation, the matter that came together to form the Earth distributed itself in a disk shape, with a slight bulging at the equator and a flattening at the poles. As this disk rotated, the conservation of angular momentum dictated that its rotational velocity had to increase as its size decreased. This means that as the cloud of gas and dust from which the Earth formed collapsed under its own gravity, its rotational speed had to increase in order to conserve angular momentum. As a result, the Earth solidified into a sphere, retaining the rapid rotation it had acquired during its formation.