Why the image turns upside down

Light travels in straight lines through the opening. Rays from the top of a scene pass through the hole and land low on the back wall; rays from the bottom land high. The same crossing happens side to side, producing an inverted projection. Because the hole admits only a narrow bundle of rays from each point in the scene, those bundles stay separated instead of spreading into a blur.

The tradeoff hidden in the hole

Making the opening smaller can sharpen the projected image, but it also lets in less light. Make it too small and light waves spread as they pass the edge—a blur-producing effect called diffraction. A larger opening brightens the picture but allows rays from each point to fan out more, softening detail. The clearest result comes from balancing these effects, not simply making the hole as tiny as possible.

The distance from the hole to the back wall also matters: a longer box makes a larger image, but spreads the available light over more area. With no lens to gather light, pinhole photographs often need a long exposure. Yet the camera does not need to be refocused for every subject distance: its narrow ray bundles keep near and far objects reasonably sharp at once. That makes the pinhole camera a simple demonstration of how image formation depends on controlling light, not on glass alone.