Gold is extremely rare. According to all geological experience it is found almost entirely in low concentrations in rocks.
Nuggets are an exception, but account for the tiniest portion of discovered gold. Interestingly there is also gold in solution in seawater, however although the aggregate quantity is large (because the oceans are huge), the concentration is low and renders extraction beyond any reasonable technology. The cost of pumping 1,000 tonnes of seawater for processing would considerably exceed the tiny amount of gold it would yield.
Gold's average concentration in the Earth's crust is 0.005 parts per million. The technology of extraction is expensive primarily because the process always requires the manipulation of large physical quantities of ore for small results. The energy required to heave, grind and process ore is itself valuable and places a lower limit on the quality of ore which can be profitably worked. Rising energy costs always impact mining viability.
At different points concentration of minerals within the earth's crust varies from their average, and it is those variations which produce workable ores. Iron, for example, accounts for an average 5.8% of the content of the Earth's crust. It needs to be concentrated by natural variations to about 30% to be considered an ore, indicating a required geological concentration of about 5 times. A lower grade gold ore would contain something like 5 grams per tonne (5 parts per million). So gold ore needs to be concentrated by about 1,000 times above the average to become viable.
The process of gold concentration happens both above and below the surface of the Earth. On or near the surface there is alluvial gold which has been concentrated by the effects of running water, for example in rivers. Because of its extreme density gold will readily fall out of suspension as water slows down. So where a river cuts through gold bearing rock, and then slows down as it hits a flatter/wider river bed, gold will concentrate in a 'placer' deposit, allowing extraction of gold particles by panning and the modern day industrial equivalents. The California Gold Rush of 1849 grew out of the gold deposits on the Sacramento river which were particularly accessible to this technique.
Underground gold veins or 'lodes' are produced in association with various metallic deposits, often including sulphides and pyrites. Gold concentration may occur as other minerals are leached away over a long period. Ore of sufficient yield is very rare.