  Passing current at given threshold voltages through a metal/insulator/metal
sandwich structure device may change its resistive state. Such resistive
switching is unique to nanoscale devices, but its underlying physical mechanism
remains unknown. We show that the different resistive states are due to
different spontaneously charged states, characterized by different `band
bending' solutions of Poisson's equation. For an insulator with mainly donor
type defects, the low-resistivity state is characterized by a negatively
charged insulator due to convex band bending, and the high-resistivity state by
a positively charged insulator due to concave band bending; vice versa for
insulators with mainly acceptor type defects. These multiple solutions coexist
only for nanoscale devices and for bias voltages limited by the switching
threshold values, where the system charge spontaneously changes and the system
switches to another resistive state. We outline the general principles how this
functionality depends on material properties and defect abundance of the
insulator `storage medium', and propose a new magnetic memristor device with
increased storage capacity.
