All of the gold found on Earth came from the debris of dead stars. As the Earth formed, heavy elements such as iron and gold sank toward the planet's core. If no other event had occurred, there would be no gold in the Earth's crust. But, around 4 billion years ago, Earth was bombarded by asteroid impacts. These impacts stirred the deeper layers of the planet and forced some gold into the mantle and crust.
Some gold may be found in rock ores. It make occur as flakes, as the pure native element, and with silver in the natural alloy electrum. Erosion frees the gold from other minerals. Since gold is heavy, it sinks and accumulates in stream beds, alluvial deposits, and the ocean.