Where does water come from? How was it first created?
A molecule of water is made of three atoms: two atoms of hydrogen (chemical symbol H), and one atom of oxygen (symbol O), hence the chemical symbol of water is H2O.
Hydrogen is the simplest atom: it contains one proton and one electron. It is also the most abundant element in the universe: more than 90% of all atoms in the universe are hydrogen atoms. Despite being the lightest atom, about 74% of the mass of "normal" (as opposed to "dark") matter in the universe is Hydrogen.
Hydrogen was created about 3 minutes after the big bang. The infant universe was very dense and hot. Thus, it couldn't contain any atoms, as they would immediately been destroyed by violent collisions with the other ingeredients. It contained a soup of photons, nucleons (protons and neutrons) and electrons. As time elapsed, the universe expanded and cooled. At a certain point it was cold enough so that protons and electrons could merge together, and atoms were formed. Clearly, the simplest atoms, which are the hydrogen atoms, were formed in the largest numbers. Much smaller fractions of heavier atoms, such as Helium (that contains 2 protons and 2 electrons) and Lithium (3 protons, 4 neutrons and 3 electrons) were also formed at the same time. In fact, the relative abundances of these light elements is (relatively) easy to calculate, and is in excellent agreement with observations. This is one of the proofs of the big bang theory.
However, Oxygen atoms are much heavier: they contain 8 protons, 8 neutrons and 8 electrons. Such heavy atoms could not have been formed during the big bang - the universe cooled down too rapidly to enable their formation. Instead, the heavy elements – including all the atoms that we are made of - were created in the stars in a process called nuclear fusion, that takes place when the temperatures ar eextermely high.
A star, like our sun, is fuelled by nuclear fusion. Essentially, in the core of the sun, 4 atoms of Hydrogen merge together to form one atom of 4He (A Helium atom contains 2 protons and 2 neutrons, hence the "4"). However, the mass of the 4He is slightly less than the mass of 4 Hydrogen atoms. The rest of this mass is converted to energy, in accordance to Einstein's famous formula E=mc2. This is the source of energy of the sun (a similar mechanism works in Hydrogen bombs).
The continuous "burning" (*) also stabilizes the sun (as well as all the stars): while gravity pushes the stellar material inward, the heat produced by the hydrogen burning at the stellar cores causes a large pressure that exactly balances it. If, for example, the rate of fusion is slightly increased, then the internal heat is increased, hence the interior pressure increases - which causes the stellar core to expand, resulting in reduction of the fusion rate.
But what happens once the Hydrogen fuel is exhausted? (No worries, for our sun it will take >4 billion years before this happens...) At this point, no heat can be produced by Hydrogen burning to counter the gravitational pull, and the stellar core shrinks. However, as this happens, the stellar core gets hotter, until eventually the Helium starts burning (fusing) into Carbon atoms, releasing some more energy that re-heats the core and halts the gravitational collapse. Then the Carbon itself starts burning, producing even heavier elements, such as Oxygen and Neon; etc. This way, all the elements - including Oxygen, up to Iron (56Fe) are produced at the core of stars.
Production of elements heavier than Iron by fusion of lighter elements does not release energy, but requires energy. Thus, once Iron is formed, no additional fusion can be used to support the star against the pull of gravity. Its core thus eventually collapses. However, if the star is massive enough (but not too massive), the collapse of the core may cause violent expulsion of the outer layers of the star resulting in a supernova. During this explosion, the elements that were synthesized at the stellar core are released (and elements heavier than iron are produced). These include, of course, the Oxygen, the essential composition of water. These processes also explain the catchy and colourful phrase that: we humans are, all of us, composed of stardust.
Thus, the hydrogen originates at the dawn of the universe (at the big bang) and the Oxygen was produced in stars that exploded. Their known abundances in the universe are in excellent agreement with theoretical models of the big bang and of stellar evolutions. But how did these elements - combined in the form of water - actually got to earth? This is a different question, whose exact answer is not yet certain. It could be either present here when the earth was formed, or arrived to the young earth by comets and water-rich meteorites. The exact answer for this question is yet to be discovered.
(*)It is not exactly "burning", since no oxygen is involved.