How the Same Color illusion works
Squares A and B are exactly the same gray. The screen sends the same light from both. Your brain is what makes them look different.
Your brain judges paint, not light
Your eye measures how much light comes from each square. That amount depends on two things: the paint on the square and the light falling on it. A white shirt in the shade can send less light than a gray shirt in the sun. Your brain wants to know the paint, so it takes the lighting into account. Scientists call this lightness constancy.
Two clues fool it
The first clue is the shadow. Your brain sees the ball’s shadow over B. It knows B gets less light, so it decides B must be painted light. A sits in full light, so the same amount of light means A must be painted dark.
The second clue is the neighbors. A is surrounded by light squares, which make it look darker. B is surrounded by dark squares, which make it look lighter. This is called simultaneous contrast.
Why it is not a mistake
In real life this guess is almost always right. It lets you see a black cat as black in the sun and in the shade. The picture fools you only because its colors were picked to match. The scientist Edward Adelson drew a famous picture like this in 1995, called the checker shadow illusion.