Short answer
Three types of cone in the retina respond to broad, overlapping ranges of wavelength. Their relative responses are recombined into opponent channels — red against green, blue against yellow, light against dark — and the brain interprets those signals in the context of the whole scene, discounting the illumination and exaggerating differences at edges.
The retina carries two kinds of photoreceptor. Rods are extremely sensitive to light but come in only one type, so they cannot distinguish wavelength — they support vision in very dim conditions but carry no colour information. Cones need considerably more light and come in three types with different spectral sensitivities. This division is why colour drains away in near-darkness: below a certain light level the cones stop contributing and vision becomes effectively monochrome, an effect anyone who has looked at a garden by moonlight has noticed.
The three cone types are usually described as long, medium and short wavelength. Their sensitivities overlap heavily — the long and medium types especially — so almost any light stimulates more than one. Colour is encoded in the *ratio* of their responses rather than in any single one firing. Because three numbers cannot capture a whole spectral distribution, different distributions can produce identical ratios and therefore look identical, which is the origin of metamerism.
Colour vision deficiency usually arises when one cone type is missing or shifted in sensitivity, reducing the distinctions available. It is common, particularly in men, and varies considerably in kind and degree.
Cone signals are not sent to the brain unchanged. They are recombined into opposing pairs: roughly red-versus-green, blue-versus-yellow, and light-versus-dark. This explains several things that a simple three-channel model cannot. It is why there is no such thing as a reddish-green or a bluish-yellow — the channel cannot encode both ends at once. It is also why afterimages take the complementary colour: fatigue one side of a channel by staring at a colour, and the other side dominates briefly when you look away.
Perception is continuously recalibrated. Chromatic adaptation adjusts to the prevailing illumination so that a white sheet of paper still reads as white under warm indoor light and cool daylight — a process called colour constancy, which works well enough that most people never notice how differently lit their day has been. Simultaneous contrast pushes a colour's appearance away from its surroundings. Together these mean the same physical stimulus can produce different experiences, and different stimuli the same experience, depending entirely on context.
Wavelength ranges and perceptual thresholds are given as approximations: both vary between individuals and with viewing conditions, and sources differ on exact boundaries. Where a figure is contested or unavailable, this page says so rather than picking one.