All the gold on Earth of for that matter all the gold in our universe came from the explosions of supernovae billions of years ago. When our universe was born in the Big Bang the only element that existed then was hydrogen, and all the other elements were built from this single building block by the process of nuclear fusion. The next element formed was helium that is composed of two electrons, two protons and two neutrons. The rest of the elements were built from these simple building blocks including gold.
Our solar system was formed out of a cloud of cosmic dust that included all the elements that we were ever going to have including gold. This cloud assumed a disk shape where as the result of gravitational collapse the sun appeared first surrounded by the leftovers that as eddies developed in the cloud produced the planets by further gravitational collapse. All the bodies whether they were asteroids, comets, meteors, moons, planets or whatever were formed from the leftovers including gold.
The force of gravity collapsing caused this steller material to heat up causing the heavier elements to become segregated, and migrating to the center of the planets including the earth. This migration of elements was also a function of the atomic radius of the various elements. Iron and nickel having relatively small atomic radii formed the center of the earth. Elements with larger atomic radii like gold and other metals remained behind in the mantle of the earth.
One of the prominent features displayed by our planet is the development a circulation of heated mantle that allowed molten magma to surface in the form of hotspots that are still with us in places. Eventually however they merged to form the so-called spreading centers where basalt rises up from the mantle driving the phenomenon we know as plate tectonics as well as creating the part of the crust we know today as seafloor.
The seafloor contains all the elements found on Earth in various proportions including gold. This part of the crust isn’t watertight allowing ocean water to penetrate it for a depth of several miles. This water contains several dissolved salts that under the conditions encountered deep in the crust of the earth can raise this brine to a heat greater then 1,000 Celsius that leaches the various metals out of the crust.
At the spreading centers the dissolved elements including sulfur that combines with most of the metal ions forming sulfides. However there are a few metals like gold and the platinum group metals that do not combine with sulfur that are called “noble metals” that are precipitated from their metal chloride state when they are cooled sufficiently. These metals are deposited with the metal sulfides around the black-smokers found associated with the spreading centers.
The crust of the Earth varies in thickness from six to twenty kilometers in thickness, and is composed of two types of crustal material that are called by geologists “sial” and “sima.” Sial is composed of rocks that are rich in silicon and aluminum that forms continental crust. Sima is composed of rocks that are composed of silicon and magnesium rich rocks that form oceanic crust. Sial is less dense then sima, so it floats on its surface.
A subduction zone is represented by a long deep trench that is parallel to a continental mass where the sima dives under the sial carrying with it not only all the elements that were deposited on its surface by precipitation from the black smokers, but also vast amounts of oceanic water entrapped within the sima. As the sima plunges further into the mantle it is dewatered by the increasing pressure, and heated once again where the water assumes temperatures approaching 1,000 degrees Celsius.
Most subduction zones dip steeply under an adjoining plate where it reaches a depth where some of the lighter elements mainly aluminum and silicon become molten the further from the edge of the inland plate the composition of the magma changes from a mixture of basalt and granite called Andesite named after its type locality the Andes mountains. The further landward the composition of the magma changes as it loses magnesium in relation to aluminum.
Before any magma forms the heat and pressure have raised enough to dewater the subducted rock forming volatiles that are charged with chlorine, sulfur and various metal ions. This is where most of the gold that was deposited on the surface of the oceanic crust by the action of black smokers is remobilized. Some of it however is released into the environment as VMS deposits from the various types of magma.
The high temperatures reached in the volatiles causes the brine to become extremely corrosive that dissolves all the metal ions including gold. Most of the metals however will combine with sulfur forming deposits of metal sulfides. Other then some rare compounds the gold is deposited from the chlorine rich brine as the native metal, this is metallic gold that is deposited when the volatiles (hot water) reaches a temperature between 100 and 300 degrees Celsius depending on the chemical conditions of the rock where it is deposited.
Native gold is usually alloyed with other metals especially silver and copper. Gold has an affinity for quartz and many gold deposits are composed of gold embedded in qiartz. Gold also occurs in VMSs where gold is often found coating the interfaces between the crystal faces of the sulfides especially pyrite.
A considerable amount of gold can also occur in marble where it is disseminated through the body of the rock. The gold deposits in the Carlin Trend in Nevada are this sort of deposit where the gold occurs in microscopic masses through the marble in such a small size they are only visible through an electron microscope.