Learning the basics of quantum theory, one thing I can't quite grasp is how quanta, especially the e=hf equation, works within the law of the conservation of energy. I imagine the heat death of the universe for example, and taken to the extreme end all masses have been converted to energy, bosons, quanta, and what we have is an ever expanding universe essentially of photons. Presumably, all those photons are stretching out as the universe expands, but given e=hf, that would mean each of those stretching (lower frequency) photons are losing energy with time, and since the universe is nothing but these photons, it would seem the entire universe would be losing energy with time. I know there's a fallacy in here somewhere. Maybe there can't be a universe just of photons? Or a stretched photon has less energy by e=hf but more potential energy that e=hf doesn't recognize? Or since photons aren't conserved each photon in the expanding universe does indeed have less energy, but there are more photons created as the universe expands, or something else? Thanks for bearing with me, appreciate any help.