One theory is that the earth was formed by two planets colliding. The two cores merged and the extra floating space debris formed into the moon.
Typically, when two planets collide an immense amount of energy is released – like billions and billions of nuclear bombs all going off at the same time. Both planets would explode into dust and rock bits, but then would combine to form one new planet. And possibly a new moon or two. All the debris would swirl around in circles until it collected together around a single core, which would form the center of the new planet. The lighter rocks and material would settle near the surface, with a ring of additional rocks floating in a ring in space. The ring could eventually form a moon.