After the big bang the hot dense state of the universe was full of photons which interacted with the matter in the universe. At a certain time this interaction stopped due to the lower temperature of the universe and these photons were allowed to propagate freely, at this point these photons were gamma rays. At present the universe has expanded, redshifting these photons so that they are microwaves