The chameleon's uncanny ability to change color has long mystified people, but now the lizard's secret is out: Chameleons rapidly change color by adjusting a layer of special cells nestled within their skin.

Unlike other animals that change color, such as the squid and octopus, chameleons do not modify their hues by accumulating or dispersing pigments within their skin cells, researchers report in the journal Nature Communications. Instead, the lizards rely on structural changes that affect how light reflects off their skin.

To investigate how the reptiles change color, researchers studied five adult male, four adult female and four juvenile panther chameleons (Furcifer pardalis), a type of lizard that lives in Madagascar. The scientists found that the chameleons had two superposed thick layers of iridophore cells — iridescent cells that have pigment and reflect light. [See photos of color-changing chameleons]

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The iridophore cells contain nanocrystals of different sizes, shapes and organizations, which are key to the chameleons' dramatic color shifts, the researchers said. The chameleons can change the structural arrangement of the upper cell layer by relaxing or exciting the skin, which leads to a change in color. For instance, a male chameleon might be in a relaxed state when it's hanging out on a branch, and in an excited state when it sees a rival male.

"When the skin is in the relaxed state, the nanocrystals in the iridophore cells are very close to each other — hence, the cells specifically reflect short wavelengths, such as blue," said study senior author Michel Milinkovitch, a professor of genetics and evolution at the University of Geneva in Switzerland.

When the skin becomes excited, the distance between neighboring nanocrystals increases, and each iridophore cell reflects longer wavelengths, such as yellow, orange or red, Milinkovitch said. The lizards' skin also contains yellow pigments, and blue mixed with yellow results in green camouflage.

Furthermore, the researchers found a deeper and thicker layer of skin cells that reflect a large amount of near-infrared sunlight. While these cells do not appear to change color, it's possible that they help the chameleons reflect heat and stay cool, the researchers said.

— Laura Geggel

This is a condensed version of a report from LiveScience. Read the full report. Follow Laura Geggel on Twitter. Follow LiveScience on Twitter, Facebook and Google+.