Guns are very loud, even in an open field. In a trench or inside a city, I can only imagine they would be louder, and quite capable of causing hearing loss. How have armies ensured that their troops weren't all deaf by the end of the first battle or even bootcamp? I'd imagine cotton balls would help but I've never seen that mentioned in books or other media.
Until the 1940s, it was believed that the cure to loud noises was developing a tolerance to them:
The pervasive attitude of the early 1900s was that hearing loss could be prevented by developing a tolerance to noise. Consequently, any attempts to avoid loud sounds or to protect oneself from them were interpreted as weakness.
Between 1941 and 1944, the US Army finally put this theory to the test:
This “tolerance” theory was scientifically examined in 1941 when the US Army opened the Armored Medical Research Laboratory at Fort Knox, Kentucky. This laboratory completed a landmark study in 1944 resulting in the recommendation that gun crews, gunnery instructors, and others regularly exposed to gunfire blasts be provided hearing-protective devices. The hearing protector of choice was the V-51R, single-flange earplug. Although hearing protection was now being considered, it still was not deemed a requirement.
It wasn't until the advent of the Air Force that hearing protection really became significant:
Even though World War II was a major contributing factor in the evolution of hearing conservation, it was not until after the war that the most significant event occurred. The Army Air Corps became a separate branch of service from the US Army and was renamed the US Air Force. Concurrently, this new branch of service introduced the jet engine aircraft to the military. No sound of that volume and duration had ever before been experienced. It was immediately noted that exposure to jet engine noise caused permanent hearing loss in a brief time. It also made verbal communication impossible and caused a series of physical manifestations described as “ultrasonic sickness.” Symptoms included earache, headache, excessive fatigue, irritability, and feelings of fear. Initially, it was believed that these symptoms were caused by inaudible, ultra-high-frequency sounds being generated by the jet engines. These symptoms, widely reported by air force maintenance crews, triggered a medical study that revealed that the illness was real; however, research attributed it to high levels of audible frequencies.
Finally, the first regulation was established in 1948:
As a result, the US Air Force published the first military regulation on hearing conservation in 1948. AFR 160-3, “Precautionary Measures Against Noise Hazards,” is significant not only because it was the first enforceable regulation in the history of hearing conservation, but it also placed responsibility for the new program on the medical leadership at air force installations. Some of the preventive measures described in AFR 160-3 include limiting noise exposures in terms of overall sound levels and using cotton wads moistened with paraffin as hearing protection for exposures to hazardous noise.
So, for the United States at least, it wasn't until 1948 that preventative measures against the hearing loss of soldiers were really taken seriously.
In Germany Maximilian Negwer founded the company "Fabrik pharmazeutischer und kosmetischer Spezialitäten Max Negwer" in 1907. The first package of Ohropax noise protectors was sold in autumn 1908 for one Goldmark (adjusted for inflation about €5.75).[…]
In August 1914, the product was recommended by Lieutenant General Freiherr von Dinklage to the War Ministry for use in the military. In 1916 the military introduced Ohropax. This was the first time that large sections of the population got to know the product, making Ohropax noise protectors the company's main product.
Translated from the sources: Wikipedia: Ohropax & Siegeszug von Ohropax begann im Ersten Weltkrieg
These plugs were initially made of wax and reduced the noise by up to 27dB. That would aid somewhat in sleep ability, but compared to noise near a gun of up to 170dB this is obviously a long way from really protecting the health of a hearing system.
This video shows Hermann Göring unplugging these protectors after he landed his plane during the last year of the First World War.
Plain and simple hearing loss and symptoms ranging up to shell shock are listed as reasons for introducing them. Previously it seems that communication ability, even if it required extremest forms of shouting were preferred and just covering the ears with your hands the only option available, despite age old stories about Sirens, Ulysses and wax. Also note that not nearly all troops would have had access to these protectors, exact numbers of plugs delivered being lost.
All this before scientific evidence could be objectively measured:
Even though damage to the inner ear by noise had been demonstrated in the 19th century, otologists could only give approximate estimates of hearing acuity in noise-exposed people, because an accurate and reproducible method of measuring hearing loss was not available until German scientists demonstrated an electronic audiometer in 1919.
Hearing protection devices (HPDs), used to guard the human ear against incurring hearing loss due to noise, have been in existence at least since the early 1900s […] In fact, in 1911, the famous band leader John Phillip Sousa complained to his friend and fellow skeet trapshooter J. A. R. Elliott that shooting traps “took a toll on his ears and was beginning to affect his livelihood [as a musician].” Elliott, being an inventor, then developed and patented (in eight countries, no less), the “Elliott Perfect Ear Protector,” and it became a commercial success (Baldwin 2004).
From: John G. Casali: "Hearing Protection Devices: Regulation, Current Trends, and Emerging Technologies", in: Colleen G. Le Prell et al.: "Noise-Induced Hearing Loss Scientific Advances", Springer, 2012, p 257–283.
Before modern research into noise induced hearing loss started really in the 1940s:
How has hearing loss been avoided in war?
But it really wasn't.
And it really isn't.
VA reported that the 2.5 million veterans receiving disability compensation at the end of fiscal year 2003 had approximately 6.8 million separate disabilities related to their military service (Veterans Benefits Administration, 2004). Disabilities of the auditory system, including tinnitus and hearing loss, were the third most common type, accounting for nearly 10 percent of the total number of disabilities among these veterans.
From: Larry E. Humes et al.: "Noise and Military Service. Implications for Hearing Loss and Tinnitus" 2006.
There are only two realistic options to protect ears from the noise of gunfire: keep away from guns, or don't use them.
A personal experience: as a recruit in the South African Army (1980), I used to be issued disposable wax plugs on range days - well, actually only one. I had to share (a great way for the Army to cut costs - I'm sure they saved millions). I would, under instruction, tear this one plug in two, warm the wax by rolling it in my hands, and stuff my ears with them. Not a great solution - the wax would block all sounds, including the instructions of raging range officers, and it would also attract dirt and dust. So it was quite a mess after a few hours of use. There was also no way of storing it during use: once the packet was opened, it went into your ear, and then into the dust bin. So, we'd wear them to lunch.
Roll forward a few years (1983, or thereabouts), and the Army decided to splurge out on disposable foam plugs. We had to roll these up into tight, thin tubes before inserting, so that the plug could expand in the ear canal. It was a better solution than the wax plugs - except, they were canary yellow. Not great for camouflage.
Being mechanized infantry, when in the turret of my vehicle, I would wear a special helmet with integrated communications - this included muffler-styled ear pieces. This was dead handy, since my 'office' was right next to a 20 mm auto-cannon with a coaxial medium machine gun on the other side of it. Whenever the guns fired, the reports inside the confines of the metal box that was the turret were... well, deafening (without the helmet, it was worse). Even so, I had to remove the helmet before leaving the turret, since the helmet was connected to the communication system by a rather sturdy 'curly cord'. Once outside, it was business as usual for me.
Business as usual was: none of us ever wore ear protection. And here I am today: in spite of 12-years service, I'm as fit as a fiddle with perfect hearing. But is it just me, or do you also hear that ringing noise?
Not exactly primary sources, lol, but Forester & O'Brien are widely regarded to have been sticklers about getting the technical and historical details right in their novels of the Napoleonic era, and the gun crews are depicted as wrapping scarves around their heads (like a "doo rag"), covering their ears for this specific purpose. Not to say these guys were 100% perfect (they both accepted the weevily hard tack myth at face value), but they clearly made an effort way beyond those of most authors of historical fiction and have been lauded by specialized historians for that reason. You see those head rags in a lot of old paintings too.