The hen's breed decides the shell color.
Shell color is genetic. White Leghorns lay white eggs, Rhode Island Reds and Plymouth Rocks lay brown eggs, and Araucanas and Ameraucanas lay blue ones. A common rule of thumb is that hens with white earlobes lay white eggs and hens with red earlobes lay brown, though there are exceptions.
The color is added late in the egg's journey. Every shell starts out white, and brown hens coat it with a pigment called protoporphyrin in the last few hours before laying. That's why brown eggs are often white on the inside of the shell. Blue eggs are different: the pigment, biliverdin, runs all the way through the shell.
Color tells you nothing about flavor, nutrition or freshness. Brown eggs often cost more because the breeds that lay them tend to be larger hens that eat more feed.