Beginning with the earliest American settlements and continuing into the 18th century, most barns weren't painted at all. Early American barn builders took sun exposure, temperature, moisture, wind, and water drainage patterns into account when placing and building barns, and they seasoned the wood (that is, they reduced the moisture content) accordingly. The right type of wood in the right environment held up fine without any paint.
Toward the end of the 1700s, these old-school methods of barn planning and building fell by the wayside. People sought a quicker, easier fix for preserving their barns—a way to coat and seal the wood to protect it from sunlight and moisture damage. Farmers began making their own coating from a mix of linseed oil (a tawny oil derived from the flax seeds), milk, and lime. It dried quickly and lasted a long time, but it didn't really protect the wood from mold and wasn't quite like the "barn red"we know today—it was more of a burnt orange, really.
The problem with mold is that it decays wood and, in large quantities, can pose health risks to people and animals. Rust, it turns out, kills mold and other types of fungi, so farmers began adding ferrous oxide (rusted iron) to the linseed oil mix. A little bit of rust went a long way in protecting the wood, and it gave the barn a nice red hue.
By the late 19th century, mass-produced paints made with chemical pigments became available to most people. Red was the least expensive color, so it remained the most popular for use on barns, except for a brief period when whitewash became cheaper and white barns started popping up. (White barns were also common on dairy farms in some parts of Pennsylvania, central Maryland, and the Shenandoah Valley, possibly because of the color's association with cleanliness and purity.)
Throughout Appalachia (a historically poorer region), many barns went unpainted for lack of money. In the tobacco regions of Kentucky and North Carolina, black and brown barns were the norm, since the dark colors helped heat the barn and cure tobacco.
Today, many barns are still painted the color traditionally used in a given region, with red still dominating the Northeast and Midwest.
This story was updated in 2019.