In the age of sail, when the weather turned blustery and cold, a sailor turned to his trusty flannel shirt to keep him warm. While he might also don a knit woolen frock or pea jacket on top, the bottom layer was invariably a shirt of red or white wool flannel.
US Navy purchasing records from the early part of the nineteenth century suggest that flannel shirts were among the most common garments owned by sailors. Boston merchant tailor Isaac Cook supplied four hundred flannel shirts for Constitution in 1814. Each cost $2.25.  The same tailor later explained that his flannel shirts were “to be made of all wool flannel of middling quality.” A Miss Sally Binney (with help from her friends) made an additional two hundred shirts of “British flannel” for the ship. This material must have been of higher quality, because she charged $2.80 per shirt. 
Shirts took more abuse than any other garment. Worn next to the skin, they kept body oils and grime from soiling other clothing. Shirt makers typically sewed with tight, close stitches and felled, or encased, the raw edges of the cut fabric. This kept seams from rubbing in uncomfortable places, but it also gave the garments the strength they needed to survive repeated scouring with a brush and soap.
As with other garments purchased by the US Navy, shirts were probably made to an established pattern. Little in the way of hard specifications have come to light for the early part of the nineteenth century, although measurements for US Army shirts of the period do exist. War Department contracts suggest that the shirts were made in the fashion of common shirts worn by laboring men everywhere. They were assembled from a series of rectangle and squares of fabric which allowed the greatest economy in cutting. By the 1830s, US Navy flannel shirts were made in two sizes, one 35 inches long and the other 37 1/2 inches long. 
For years, naval surgeons argued that wearing flannel shirts and drawers next to the skin was the best defense against sickness, and by the second decade of the nineteenth century, this had become canonical advice in naval circles. One medical textbook explained that a seaman’s clothing had a direct effect on his “humors.” According to the author, “a flannel shirt is an article essential to a seaman. When it is considered how often sailors are roused from profound sleep, and that in the midst of the perspiration usual in that state, they are at once exposed to the night air, to rain, and to cold, it is impossible that they must not suffer from such a change, unless their bodies are fortified by that best of coverings, flannel next the skin.”
By the 1830s, red flannel seems to have eclipsed white in popularity. Certainly most of the surviving images of sailors in red shirts date to the middle decades of the nineteenth century. Most of these also depict merchant seamen. In the US Navy, however, new uniform regulations and calls for ever more uniformity among the enlisted men spelled the end of the once-popular garment in the service. Perhaps because of their association with whalers and merchant seamen, the red flannel shirt began to conjure images of greasy blubber boilers or packet rats. One American naval sailor found the newly-imposed regulations especially draconian: “In an English man of war, at sea, the men are permitted to wear almost any kind or color of clothes that they please. Wearing a Scotch bonnet, (so common among seamen,) or a checked or red flannel shirt, would, in our service, subject the wearer to ‘drinking with the ducks’ or getting ‘ his back rations’ in the gangway.”  That is to say, he’d have his grog stopped or get flogged for daring to wear a red flannel shirt!
Despite the downfall of their red counterparts, white flannel shirts continued to be issued out of Navy slop clothing stores through the 1840s, until they were superseded by the familiar blue frock with its wide collar in the years before the Civil War.
As an interesting side note, St. Nicholas is not only the saint of children, but of sailors. And what does he wear when he makes his epic yearly gift-giving voyages? Why, a red flannel suit, of course!
 Isaac Cook to John Rodgers, 12 March 1816, in Proposals, Reports, and Estimates for Supplies and Equipment, 1814-1833, RG 45, E 328, vol.4, NARA.