The faintly derogative epithet "son of a gun" has been documented as part of the lexicon of the English language since 1708, but no one can really lay claim to knowing how it began or what the phrase originally signified. Numerous interesting backstories have emerged in the centuries since, and it's possible one might even be the right one, but we no longer have any way of knowing. We can, however, dismiss some of the more fanciful "explanations" that have come along:
- The phrase "son of a gun" originated on ships in the early 18th century, when women were allowed to accompany their husbands or new boyfriends on long sea voyages. During such voyages, mothers gave birth to their children behind a canvas curtain near the midship gun. If the paternity of the newborn was in doubt — and often it was, as many of the women were prostitutes — the child was facetiously registered in the log as the "son of a gun."
- When in port, and with the crew restricted to the ship, women were allowed to live aboard. Sometimes children would be born on the ship, and a convenient place for giving birth was between the guns on the gun deck.
- Life on board a British man-of-war was hard for the wife of a sailor: she shared her husband's hammock and his daily ration of salted beef, dried peas, hardtack, and cheese while staying out of the way of daily activities. One of the most difficult inevitable consequences of wives following their husbands to sea was childbirth. The term "son of a gun" resulted from the firing of a ship's guns to hasten a difficult birth.
- In the instance of a difficult birth (on land this time), the assistance of nearby military bases would be solicited. They'd be persuaded to fire one or more of their cannons, the noise of which would startle the distressed woman sufficiently to induce labor.
We can dismiss many of the recurring elements in the four fanciful explanations touted above. First, wives and girlfriends (i.e., prostitutes) were not routinely brought along by ordinary sailors on naval vessels which were often out on a commission for months or years at a time. Can you imagine how much extra space would have to be built into these ships, and how many extra rations they'd have had to carry, if all crew members brought their wives and girlfriends along? And where did these women stay? There was barely enough room below decks to accommodate the regular crew (even though only half the crew was ever asleep at once), and women couldn't be out on deck where they'd interfere with the operation of the ship. Were they just all stuffed into the hold for six months at a time?
Yes, some officers on some voyages were permitted to bring along wives, but this happened infrequently at best, making the presence of non-passenger females (pregnant or otherwise) aboard sailing ships unusual. The vast majority of such voyages had nary a female aboard, thus the notion that a popular phrase sprang from the common occurrence of women's so overrunning vessels that they were routinely whelping on the high seas is seriously flawed. (Larger naval vessels often included a berthing deck which was distinct from the gun deck. This is where the crew on such ships would sleep, not amidst the guns on the gun deck.)
Second, we should look askance at the claim that when in port, and with the crew restricted to the ship, women typically gave birth aboard ship. Crews were usually restricted to ship only in hostile ports, which we can fairly assume their home berths were not. And even when shore leave was denied because the captain was intent upon being underway quickly and feared losing some of his crew (either to desertion or drunkenness) if they were let off the ship, the wives were under no such restrictions. Not being necessary to the running of the ship, nothing would have prevented expectant lasses from returning to their homes to give birth. Their husbands not only wouldn't accompany this hypothetical exodus, they wouldn't have wanted to even if they could. In the era of sailing ships, the role of the father during the birth process was not what it is now — dads of modern times may make it their business to be in the delivery room cheering matters on, but papas of more distant ages made certain to be elsewhere, and the farther away the better. Bringing babies into the world was considered wholly the province of women (doctors were summoned only if matters had taken a decidedly bad turn, and even then only rarely), and men were present at such events only when it could not otherwise be avoided. Men certainly did not voluntarily insert themselves into the proceedings, nor would their presence have been welcomed by the women straining to bring children into the world, the midwives attending them, and the array of female relatives that inevitably gathered by the bedside.
Third, although a certain convoluted train of logic might tie the firing of large guns to hastening a difficult birth (e.g., inspiration by example, a cornerstone of sympathetic magic), there's no reason to believe anyone living in those times even tried this, let alone that the practice was so widespread that the firing of guns to ease childbirth begat a distinct phrase. Histories of life in the 1700s and 1800s are thunderous in their silence about this practice, and it can safely be assumed that quiet reflects a stunning truth about the matter — that whatever tales we're now telling ourselves, cannonfire wasn't being used to hasten babies into the world.
Granted, gunfire had been employed in distant times to fend off disease (it never worked), so there is some historical basis for a tie between the discharge of firearms and medical emergencies. During the 1793 yellow fever epidemic in Philadelphia, many took to firing muskets both in the street and indoors under the mistaken assumption that introducing the acrid fumes of burnt gunpowder into the air would kill off the mysterious illness daily making away with hundreds of citizens. Such practice was even recommended by the city's government, so this wasn't even a case of a few badly-educated members of the populace seizing upon a fanciful notion; at the time it appeared to have the backing of the scientific community. However, it was the fumes of the spent gunpowder, not the report of the guns, that was supposed to effect the cure.
In the realm of superstition, sudden noise is espoused as a way to drive away evil (we toll wedding bells for this purpose, and the New Year's Eve hullabaloo springs from that same wellspring of belief), but there is only one reported tie in that area of study between abrupt racket and the induction of labor, and it involves the ringing of church bells. Rather, the canon of superstition advises the loosening and opening of items to assist during a difficult childbirth: windows are to be flung open, doors unlocked, and shoelaces undone to help the impending mother in her travails. Nothing in superstition, however, advises frightening women into giving birth, much less introducing roaring cannons into the procedure.
Another explanation for "son of a gun" ties the phrase to the reason for shotgun weddings — the child of such unions was deemed a "son of the gun." That might seem a more reasonable origin, but that meaning did not appear in connection to the term until 1922.
A more believable postulation for the origin of the term shifts the focus onto the occupation of the father and away from the location of the whelping (which fanciful lore would have us believe was on a deck between two guns, rather than in a cot in an officer's cabin or in a screened-off corner of the sick bay). In that explanation, "gun" refers to "soldier" (equating arms with the man, as it were), making any soldier's or sailor's male child — conceived in wedlock or not — a "son of a gun." Alliteration (repetition of sounds) and well-cadenced rhymes were just as well-loved centuries ago as they are now, thus our forefathers would have delighted in "son of a gun's" inherent ear appeal in the same way we were slyly pleased by "the Thrilla in Manila" and "in like Flynn."