The more distant a galaxy, the more its light is redshifted. This effect, first observed by Edwin Hubble, is one of the main points of evidence for cosmic expansion. But this redshift effect is often misunderstood. After all, if light from a distant galaxy is redshifted, and the energy of a photon depends upon its wavelength, doesn’t that mean the photon is spontaneously losing energy? What about conservation of energy?
While the energy of a photon does depend upon its wavelength, and its energy is conserved, that only tells part of the story. While energy is conserved in a particular reference frame, the amount of energy you observe can vary depending upon your frame of reference. Imagine, for example, that you are riding in a train, and you place a cup of coffee on a table. From your vantage point the coffee is just sitting in place. From your perspective it has no kinetic energy, and it will continue to sit on the table as long as the train continues to move at a constant speed. From a pedestrian standing outside the train the coffee mug (and the train) are moving along at some speed. It has some kinetic energy because of its motion. From both vantage points the kinetic energy of the coffee cup is constant, but the amount of energy seen from each viewpoint is different. The same is true with light.
Of course the redshift from cosmic expansion is different from that of relative motion. With cosmic redshift space expands between the time light is emitted and the time it is absorbed, so it seems as if the light spontaneously redshifts as it travels. What’s really going on is that spacetime is warped, giving the illusion of spontaneous redshift, just as the warping of space can cause the path of light to bend in space even though light always follows the shortest path through spacetime. The energy of a photon is still conserved along its path, even though the galaxy that emits the photon and our observation of the photon will perceive different energies.
This is why the cosmic redshift model is very different from the so-called tired light model, which assumes that light spontaneously loses energy rather than the universe is expanding. Not only does tired light violate conservation of energy, it makes very different predictions about how the universe would look. When you compare it to observation, the tired light model fails.
So even though the light from distant galaxies are redshifted, the light’s energy is still conserved.