Originally farmers avoid painting the Barnes completely as it was considered flashy and showy as back then. There were no known benefits to painting the barn other than for aesthetic reasons instead farmers like the idea finding the right wood for the right environment and carefully planning how the barn would be built.
During the late 18th century farmers moved on from this practice realizing that a cheap homemade coating made from linseed oil would protect the barns from oyster and sudden life damages. Color of this mixture was burnt orange but the problem with this coating is that it didn’t protect the wood from mold.
So the farmers had a ferrous oxide also known as Rust into the mixture which successfully killed all mold and changing the paint red. Adding ferrous oxide to the coating made the color red.
In the late 19th century red paint was the cheapest color so many people decided to buy as it already matched the theme of many barns at the time. A traditions still carried on in the modern times despite red no longer the cheapest color.