An atomistic insight into potential barrier formation and band bending at the interface between a metal and an n-type semiconductor is achieved by ab initio simulations and model analysis of a prototype Schottky diode, i.e., niobium doped rutile titania in contact with gold (Au/Nb:TiO$_2$). The local Schottky barrier height is found to vary between 0 and 1.26 eV depending on the position of the dopant. The band bending is caused by a dopant induced dipole field between the interface and the dopant site, whereas the pristine Au/TiO$_2$ interface does not show any band bending. These findings open the possibility for atomic scale optimization of the Schottky barrier and light harvesting in metal-semiconductor nanostructures.