Electrolysis is chemical decomposition produced by electricity—in this case, the chemical you’re decomposing is water.
The molecular formula for water is H2O, where H stands for the element hydrogen and O stands for the element oxygen. In a glass of water, many of the molecules naturally separate out into hydrogen ions (H+) that are positively charged and hydroxide ions (OH-) that are negatively charged. Your electrolysis device causes reactions that pull apart the water even more.
Since opposite charges attract, the oxygen-containing hydroxide ions migrate toward the positive electrode and the hydrogen ions migrate toward the negative electrode.
Elementally, both oxygen and hydrogen prefer to be diatomic, or two-atom molecules. At the positive electrode, oxygen atoms get pulled from the hydroxide ions and then combine to make oxygen gas (O2) bubbles. Likewise, at the negative terminal, hydrogen ions combine to make hydrogen gas (H2) bubbles. Below is the chemical equation that describes what happens.
2H2O(l) → 2H2(g) + O2(g)
Both oxygen and hydrogen gases are clear and odorless. So how do you know which test tube contains which gas? Here’s a clue: One filled faster than the other. There are twice as many hydrogen atoms available to form a gas, and thus the volume of hydrogen gas that forms should be greater than that of the oxygen gas.
The splint test gives another clue: Hydrogen gas is very flammable—a fact made famous by the Hindenburg zeppelin disaster—and makes an explosive popping sound when lit. Oxygen, on the other hand, is not actually flammable, but it is necessary for combustion, which is why your split relit in oxygen gas.
Epsom salt, also known as magnesium sulfate (MgSO4), is dissolved in the water to help your battery break up the water more efficiently. Epsom salt breaks up into charged particles called ions, and these help carry the electric current through the solution.