Several million years ago, plants and animals died at the bottom of then-oceans. Silt and sand hardened over the decaying organic material, trapping it beneath. Cue heat and pressure slow-cooking the remains, and transforming carbon and hydrogen into methane-rich gas, coal and oil. The gas rose through porous rock and hit impenetrable traps -- reservoirs. It collected there till geologists came along.
Geologists know which rock types are likely to contain gas; for instance a sloped surface might be a place where land folded in on itself, creating a dome shape we can see and a gas reservoir below the surface. Using seismic earthquake surveys -- or dynamite -- to explore more surface characteristics, they can also determine stable drilling places.
Shale reservoirs are worth exploring separately. Shale is fine sedimentary rock, like dried sludge that traps gas well. Since shale has low permeability, the gas can't move to more permeable rocks, making it very expensive to extract. Enter hydraulic fracturing or fracking.
In fracking, workers pump gallons of water, sand and chemicals down a well, and into the rock, which cracks under pressure. Gas escapes, travels through tunnels propped open by the sand, and is collected at the top of the well. Since fracking started a few years ago, North America's reachable gas supply has suddenly exploded. Now the U.S. has a projected 100 years' supply of gas.