There are many myths swirling around the origins and evolution of porter and stout. First there is the notion that stout and porter refer to quite different styles; while another holds that these beers were always dark, and a third tradition relies on the 'three threads' story to give porter an origin myth. All these tales are largely—and in some cases entirely—untrue.
Porter first pops up in print in the 1720s, and the assumption that its name was derived from the occupations of the manual laborers who preferred it comes from a letter by the Swiss-born César de Saussure, who wrote a series of letters from London to his family back on the continent. Topics he covered included typical 18th-century fare such as highwaymen, coffeehouses, and newspapers, but it is his mention of beer (in a letter dated October 29th, 1726) that may be partly responsible for theories of its naming:
Another kind of beer is called porter, meaning carrier, because the greater quantity of this beer is consumed by the working classes. It is a thick and strong beverage, and the effect it produces, if drunk in excess, is the same as that of wine; this porter costs threepence a pot.
It is difficult to know whether this is something of a folk-etymology (notably one possibly formulated by a non-native speaker of English), or whether de Saussure had been explicitly given that information by someone who knew more than the received wisdom of the time. But beer historian Martyn Cornell argues that the name is, indeed, associated with these hard-working people (who would have needed ample supplies of both liquid and calories to get through an average day on the job), and notes that they played a much larger role in London life than has been recognized.
There is an alternative theory, however—one that suggests that porter (or at least the practice of calling a beer 'porter') came to Britain from the Netherlands, where a beer known as 'poorter' was being consumed as early as the 14th century. Trading links between London and Dutch ports were certainly well-established, and there could well have been some cross-pollination, though further evidence that there is a direct connection is required. In either instance, though, it seems that porter and poorter were both considered ideal beers for the working classes, so it seems they are welcome to claim the name together.
Perhaps now is the best time to address the underlying stout versus porter question: were they really different beers, or simply different names for broadly similar products? Most contemporary accounts in the 18th and early 19th centuries simply use 'stout' to mean a stronger beer of just about any makeup and color, although over time it becomes applied more specifically to stronger 'brown' stouts—really, just porters with higher gravity. In 1810, Thomas Mortimer defined porter and stout this way:
Porter may be divided into two classes, namely, brown-stout, and porter properly so called. The London porter has deservedly obtained the reputation of being the best in the world; it is a wholesome, cooling and at the same time nutritive beverage.
Beer's color comes from the type of malt used, and they have long been available in a variety of 'roasts' (though only in recent decades have the options been quite so granular), depending on the maltster and the type of malt desired.
Ronald Pattinson, who, like Cornell, has been digging into brewery archives to find hard, primary source evidence, rather than beer hearsay, has found brewing logs indicating that London brewery Barclay Perkins brewed a Pale Stout—a strong ale brewed entirely from pale malt until around 1800, and Cornell finds mention of such beers in newspapers as late as the 1840s (so the trend for 'new' styles like a white stout are really more of a semantic throwback than an entirely new innovation).
And while today most associate stout with a distinctly black color, early porter and stout varied much more considerably—a truly black beer was not even an option until the invention of black patent malt in 1817. Prior to that, porter and stout were both typically made from brown malt, though depending on the brewery and circumstances, amber and pale malt was often employed as part of the grist bill as well. Some of the recipes Pattinson cites suggest that porter and stout came in a wide variety of shades—and some would have been quite clear—until public demand led to an expectation of a darker beer.
At various points in time, sketchier brewers added not-always-legal additives to modify the color of their beers, and this contributed to a somewhat downmarket reputation in some corners. But if there were any lingering doubts that porter and stout were once the same in the mind of the public, it's instructive to see this 1836 advert for 'Double Brown Stout Porter' from a brewery known as 'Guiness' (sic)—the transition to a lower-alcohol, black beer was still some way off. In short, the porter and stout, at least for a long stretch of their history, were nearly interchangeable.
And so to the 'three threads' myth. The story goes something like this: publicans in London would blend a variety of beers for their customers. Depending on the version of the story, they might be a combination of a stronger, old ale, a sour beer that may not have been sour on purpose, and a younger ('mild' or unaged) beer, or simply cheaper and more expensive beers, but generally using a blend of three. Enter one Ralph Harwood, who in the 1720s or 1730s decides to brew a beer that has this blended character, but that could be dispensed from a single cask (or 'entire butt'). Londoners rejoiced, and soon the new style was the most popular in the capitol. It's a pleasant story, often repeated, and one with almost no evidence to support it.
The three threads story's popularity comes from a guidebook published in 1802—long after porter was an established, popular beer style—and Cornell has argued very convincingly that it's purely an invention. True, Harwood was a London brewer, and like other London brewers, he made porter; it was what the drinkers wanted. But like most spurious origin myths, it's been re-printed so often that it's become the version people 'know' about how porter came about.
So, what brought about the porter/stout linguistic divide? It seems the declining quality and availability of porter may have been a factor, and that stout remained a 'respectable' alternative.
Porter became lower and lower in alcohol, thanks to the intervention of two world wars and changes in the way beer was taxed, and between the 1950s and 1970s, it became viewed as an 'old man's drink' and essentially died out in Britain, with some notable exceptions (e.g. Fuller's London Porter, as well as newer alternatives like Meantime Brewing Company, who make a variety of porters).
The idea of a stout being stronger than a porter still lingers in the popular imagination, even though the world's most popular stout, Guinness, is around 4.2% ABV (though the Foreign Extra Stout version is much closer to the earlier formulations at around 7.5%)—hardly the 'meal' some make it out to be. While porters revived in the US—and to a lesser extent in the UK, though they are still making a comeback there—they are now often considerably stronger than their stout cousins.
Of course, there are many exceptions to this: Russian Imperial Stouts, which have something of a different history from more 'standard' stouts, are very high in alcohol, and Baltic Porters similarly follow them up the ABV rankings, but as a very broad generalization, many popular modern porters run between the 5%-7% ABV mark, while stouts often follow the Guinness model and weigh in a little lower in strength. The explosion (or rebirth) of a variety of sub-styles of both porter (at least in the US, just about any dark beer may qualify) and stout (milk stout, dry Irish stout, oatmeal stout and so forth) may actually have served to remind drinkers that in the end, the naming is just semantics; if it's a good beer, brewers can categorize it any way they like, just as they did in the 18th century.