Simultaneous Contrast Illusion
Two identical gray squares look like different shades the instant you place one on a dark background and the other on a light one - proof that the brain never judges color in isolation.
What you're seeing
Two squares of the exact same gray sit on two different backgrounds - one dark, one light - in the demo above. The square on the dark background looks noticeably lighter than the square on the light background, even though a color picker (or, if you're viewing this on paper, a pair of scissors and some careful cutting) will confirm they're identical. Cover the surrounding backgrounds with your fingers so only the two squares are visible and the difference disappears instantly; uncover them and it snaps right back.
Why context overrides the raw signal
Your visual system almost never reports a color or brightness value in isolation. Every patch of your visual field is interpreted relative to what's immediately around it, because relative judgments are far more useful for identifying real objects than absolute ones. In the natural world, the amount of light bouncing off a surface into your eye depends heavily on the overall illumination - bright sun versus overcast versus indoor lamp light - so a system that reported raw brightness values directly would see the same white shirt as a wildly different color from one hour to the next. Instead, your visual cortex estimates lightness by comparison: a patch surrounded by darker material reads as relatively light, and the identical patch surrounded by lighter material reads as relatively dark. That comparison process is simultaneous contrast, and it runs automatically and unavoidably, which is exactly why simply knowing the two squares are identical doesn't make the illusion go away.
The neural basis: lateral inhibition
Part of the mechanism traces down to a genuinely low-level property of the retina and early visual cortex called lateral inhibition, where neurons responding to one point in the visual field partly suppress the activity of neighboring neurons responding to adjacent points. A gray square surrounded by a dark field receives less inhibitory suppression from its neighbors, since the dark surroundings are themselves generating a weak signal, so its neurons fire more strongly and it reads as lighter. The same gray square surrounded by a bright field gets suppressed harder by its high-firing neighbors, muting its signal and making it read as darker. Lateral inhibition alone doesn't settle the question, though - some researchers argue that higher-level inference about surfaces and illumination also contributes, similar to the debate over how much of the checker shadow illusion is "wiring" versus "inference." What's well established is that lateral inhibition accounts for a substantial part of the effect, doing exactly what it evolved to do - sharpen edges and boundaries by exaggerating local contrast - even if it isn't necessarily the whole story.
How strong the effect gets
The strength of simultaneous contrast scales with how different the two backgrounds are - a near-black background paired with a near-white one produces a dramatic difference, while two backgrounds that are only mildly different in tone produce a correspondingly mild illusion. The effect also interacts with color, not just brightness: a gray patch on a strongly colored background tends to take on a faint tint of that background's complementary color, a closely related phenomenon sometimes called simultaneous color contrast or chromatic induction.
Why this matters beyond a party trick
Simultaneous contrast isn't just a curiosity confined to lab demonstrations - it's a working principle that artists have exploited deliberately for centuries, placing colors next to carefully chosen neighbors to make them read as more vivid, more muted, warmer, or cooler than their raw pigment value would suggest on its own. It's also the same underlying local-contrast machinery that powers the checker shadow illusion, just without the added layer of an implied cast shadow influencing the judgment.
A little history
French chemist Michel Eugène Chevreul formalized the principle in his 1839 work on color theory, originally motivated by a very practical problem: as director of dye production at the Gobelins tapestry manufactory, he was fielding complaints that certain dyed threads looked like the wrong color once woven next to other threads, even though the dye batches themselves were correct. His resulting law of simultaneous contrast became foundational reading for generations of painters, textile designers, and - eventually - vision scientists studying how context shapes color perception.
Related reading
For a version of this same effect wrapped inside an implied shadow, see the checker shadow illusion; for a case where context-dependent color judgment famously divided the internet, see "the dress".