The octet rule is the fundamental explanation to give the reasons as for why atoms would undergo complex molecular and ionic arrangements, by sharing or transferring valence or bonding electrons between atoms in a compound.
It states that atoms would need to have the maximum number of electrons in their valence shell to be inactive and stable. Thus atoms would tend to bond to other atoms to achieve this Lower energy and stability.
They do this by sharing between electrons between atoms as in covalent bonds.