A new algorithm is presented to hide a secret image in the least significant bits of a cover image. The images used can be color or grayscale images. The number of bits used to hide changes according to the pixel neighborhood information of the cover image. The exclusive or (XOR) of the neighbors of a pixel is used to determine the smoothness of the neighborhood. A higher XOR value indicates less smoothness and leads to using more bits to hide without causing noticeable degradation in the cover image. Steganography is a method to hide a secret message within other information, so that the existence of the hidden message is hidden. Cryptography, in contrast, is a hidden information coding method so that unauthorized people can not recover it. The main advantage that steganography has over cryptography is that it hides the real existence of secret information, which makes it an unlikely target of espionage attacks. To achieve greater security, a combination of steganography with cryptography can be used.