Gold is a much heavier atom than iron, with 79 protons and 79 electrons in each atom. Gold is too heavy for even red giant stars to make through nuclear fusion. The only way to make gold is when a red giant star explodes in a supernova, or when two stars bang into each other. When that happens, the tremendously high temperatures of the explosion itself – hundreds of millions of degrees – force the star’s atoms to mix together. That makes gold (and other heavy atoms like uranium).
All of the gold in the universe was made during these supernova explosions. Because it’s so hard to make, there’s much less gold in the universe than there are lighter atoms like hydrogen or carbon or silica. Since gold also happens to be shiny and pretty, we think of it as valuable.