A hair is either pigmented or it's white. In fact, a person who's afraid of "going gray" as he ages might be comforted to know that gray hairs don't actually exist. Gray hair is an optical illusion -- the product of colored hairs mixed in with white hairs.
Your hair color is a product of two pigments in the hair shaft, eumelanin and phomelanin. All hair colors are a combination of these pigments. The more eumelanin in your hair, the darker it will be. The more phomelanin in your hair, the redder it will be. As described by Stanford University geneticist Barry Starr, a blond person has a little bit of eumelanin and little or no phomelanin, an auburn-haired person has a lot of eumelanin with some phomelanin thrown in, a redhead is all phomelanin with very little eumelanin, and so on.
Hair gains its natural pigmentation, its color, at the hair follicle. And like everything else about your natural appearance, the particular mix of pigments that goes into your hair is a function of genetics. As Starr notes, there's no one "hair color" gene. Hair color is a combination of the effects of many genes -- a process that's still something of a mystery even to scientists.
Your genes don't change, so as you move into late adulthood, your hair color doesn't change to gray. As you age, hair follicles simply quit producing pigment. This is called achromotrichia, and it happens as the pigment-producing cells in the follicle die and are not replaced. When achromotrichia occurs in a follicle, the pigment doesn't fade away; it "shuts off." That individual hair still grows, but it doesn't have any color at all. It's pure white--not gray.
The more white you have, the "grayer" your hair looks. It's similar to a black-and-white photo in a newspaper. When you look at such a photo under a magnifying glass, you see that it's made up of thousands of tiny black dots on a white background. Stand back, and it looks gray. Once all the hair follicles have undergone achromotrichia, your hair is completely white. Achromotrichia happens at different rates and times for different people. Some go gray or even completely white relatively early in life; others hold onto at least some color their entire lives.
Folklore is full of tales about people's hair quickly going white under severe stress. However, the exposed part of every hair shaft--the part you can see--is actually made up of dead cells. It can't change color spontaneously, though it can be bleached by the sun or environmental factors, or you can dye it. Yet "going white overnight" is possible. As health author and radio host Dr. Gabe Mirkin explains, a condition called alopecia areta can cause large amounts of a person's hair to fall out in a short period of time. When alopecia areta occurs, you almost exclusively lose pigmented hairs. The hair doesn't "turn white" --the colored ones just fall out.