A lone oxygen atom has 6 electrons in its outer shell which is not very stable, whereas as full octet (8 outer shell electrons) is stable. In order to achieve this two oxygen atoms will share 4 electrons, each contributing 2 electrons. Since these electrons exist within the orbitals of both atoms, to oxygen atoms essentially achieve a full octet.