Hey there! Hello!
In order for water to be formed, or for any reaction to occur, there needs to be something that splits the current bonds of hydrogen and oxygen up. In this case, some sort of activation energy is required.
Hydrogen and oxygen are not found as single molecules in nature. They're found as 2 molecules linked together, as H2 and O2. An activation energy, such as heat, or some sort of catalyst needs to be used in order to split the two molecules up and make them link with one another.
What happens afterwards is a chemical reaction that involves the valence electrons of oxygen (which has 6 on the outermost shell) and hydrogen (which has two on the outermost shell). The oxygen wants to have an octet (8 valence electrons) total, so it shares with the hydrogen, which is already satisfied with it's two valence electrons (according to the nature of hydrogen).
But because there has to be a total of four molecules involved, two molecules of water are going to be produced as a result.
[tex]2H+2O=2H20[/tex]
Hope this helped you out! Feel free to ask me any additional questions if you need further clarification. :-)