Volatile and nonvolatile switching are selectively operated using a two-terminal gap-type atomic switch by choosing a sweeping bias range. The amount of Ag atoms those precipitate from an Ag2S electrode in the turning-on process is a function of a bias. Using a bias larger than the threshold bias, enough number of Ag atoms precipitate to make a bridge to the counter electrode, resulting in the nonvolatile operation. A bias smaller than the threshold bias does not make a bridge, and Ag atoms return to an Ag2S electrode while decreasing a bias to zero, resulting in the volatile operation. The selective operations are enabled by controlling electrochemical potentials.