The electricity hum (also called the “mains hum”) emerges because electricity runs on alternating current (AC), which transposes voltage in the pattern of a sine wave. In the US, the frequency of this current is 60 Hz, which creates a tone almost exactly halfway between A♯ and B. In Europe, it’s 50 Hz tone, which is closer to a G. If that doesn’t mean much, let’s look at it in a bit more detail.
Alternative current
There are two types of current: direct and alternative. Direct current (DC) is a unidirectional flow of electric charge; think of current flowing from a battery, that’s DC. Alternating current, on the other hand, is less intuitive. As the name implies it, it alternates — it periodically reverses direction. Alternating current is how electric power is delivered to businesses and residences, where its voltage can be increased or decreased with a transformer.
As a result, while the voltage of direct current is a straight line, the voltage of alternating current is a wave, most commonly as a sine wave, as can be seen below.
Our modern society is pretty much built on alternating current. All the devices in our day to day life need current, and that almost ubiquitously comes as alternating current. But as James Clerk Maxwell showed in the 19th century, electrical current and magnetism go hand in hand. Sometimes, stray magnetic fields cause the enclose and accessories to vibrate, generating an electric hum. Secondary sources are magnetostriction and corona discharge around high voltage power lines.
The “hum” intensity is a function of the applied voltage, which brings us to the next point.
Current and sound
In music, a note is governed by its pitch, which is based on the frequency of the sound. The higher the frequency, the higher the pitch. Generally speaking, a scale starts with A, which is 440 Hz. If you go an octave below, you’d get another A at 220 Hz. The next (lower) A is at 110 Hz, then at 55 Hz, and so on. Since the electrical hum depends on the frequency of the current, so the sound will pretty much have the same frequency as the current. In the US, the current frequency is 60 Hz tone. The 60 Hz tone is almost exactly halfway between A♯ (58.24 Hz) and B (61.68 Hz). However, the 60 Hz frequency is pretty much only used in the Americas (mostly), Saudi Arabia, South Korea, the Philippines and about half of Japan. The rest of the world uses 50 Hz current frequency, which means that the note resulting from the electrical hum is closer to a G (a bit sharp).
Hums can also appear at the frequency harmonics, though with a much lower intensity. So in the case of a 60Hz current, you could have some humming at 120 Hz, 240 Hz, and so on, up until very high frequencies. There’s an entire spectrum of electrical hum. In terms of sound, that means you not only output the original note, between A♯ and B, but also the same note one octave higher, and another one, and so on.
Getting rid of and using electrical hum
Generally speaking, the hum is an annoyance, especially in musical instruments that involve electricity. At a venue, this electrical hum is often picked up via a ground loop. In order to fix this, stage equipment often has a “ground lift” switch which breaks the loop. An alternative way to fix this is the audio humbucker. Electric guitars especially (and sometimes microphones) use one or several humbuckers, which are basically two coils instead of one. The two coils are arranged in opposed polarity so that the AC hum is cancelled, while still producing the intended signal for the sound.
However, electrical hum can sometimes be important — especially in forensic analysis. Forensics use a technique called Electrical Network Frequency which allows them to validate audio recordings. They compare how the frequency changes in the background mains hum to a pre-existing database. Basically, they use the mains hum signal as a digital watermark which can identify when the recording was created and help detect any edits in the recording. In the German federal state of Bavaria for instance, this technique has been used by authorities since 2010.