The role of electron band bending and surface sensitivity in determining the core level binding energies by X-ray photoelectron spectroscopy is investigated. A dominating contribution of surface atomic layers to photoemission intensity is confirmed for normal photoemission. The energy of the photoelectron core level peak does not deviate from core level peak energies of electrons photoemitted from the surface atomic layers of the crystal. The higher surface sensitivity regime, achieved e.g. at off-normal photoelectron detection angle, can be used to study the surface potential barrier in just a few topmost atomic layers. In addition, it is demonstrated that core level binding energy measured by angle-resolved X-ray photoelectron spectroscopy reflect the electron attenuation anisotropy. In particular, core level binding energy changes with emission angle and correlates with the forward focusing directions in a crystal. This effect is demonstrated by measuring the polar angle dependence of Ga 3d core levels on clean GaN(0001) and GaN(0001¯) surfaces with a higher and a lower band bending, respectively. The effect is explained by variation of emission depth in a crystal for normal and off-normal photoelectron emission angles.