This work reports on hard x-ray photoelectron spectroscopy (HAXPES) of CoFeB based tunnel junctions. Aim is to explain the role of the boron diffusion for the observed improvement of the tunneling magnetoresistance ratio with increasing annealing temperature. The high bulk sensitivity of HAXPES was used as a nondestructive technique to analyze CoFeB-MgO-CoFeB magnetic tunnel junctions. The investigated samples were processed at different annealing temperatures from 523 to 923 K. Hard x-ray core level spectroscopy reveals an enforced diffusion of boron from the CoFeB into the adjacent Ta layer with increasing annealing temperature. The dependence of the tunneling magnetoresistance on the annealing temperature is explained by the combined effects of an improved crystalline structure together with a change in the spin polarization at the Fermi energy caused by the removal of boron from the CoFeB layer and Ta diffusion at high annealing temperature.