Local variations in the charge distribution at semiconductor interfaces can lead to energy level band bending in the structure’s band diagram. Measuring this band bending is important in semiconductor electronics and quantum technologies, but current methods are typically only surface sensitive and are unable to probe the extent of band bending at a depth within the semiconductor. Here, we show that nitrogen–vacancy centres in diamond can be used as in situ sensors to spatially map band bending in a semiconductor device. These nitrogen–vacancy quantum sensors probe the electric field associated with surface band bending, and we map the electric field at different depths under various surface terminations. Using a two-terminal device based on the conductive two-dimensional hole gas formed at a hydrogen-terminated diamond surface, we also observe an unexpected spatial modulation of the electric field, which is attributed to the interplay between charge injection and photo-ionization effects (from the laser used in the experiments). Our method offers a route to the three-dimensional mapping of band bending in diamond and other semiconductors that host suitable quantum sensors.