Explanation: The atoms attain the configuration of inert gas by sharing electrons.
Lets take an example of HCl,
Atomic number of H is 1 and it has only 1 valance electron. whereas atomic number of chlorine is 17 and it has 7 valance electron.
When hydrogen atom combine with chlorine atom then they share electrons through covalent bonding in order to complete their octet.
According to figure,
Electronic configuration of H = 1
Electronic configuration of Cl = 2,8,7
Now, after share of electron
Electronic configuration of H = 2
Electronic configuration of Cl = 2,8,8
Hence, we can conclude that when atoms share electrons then their octet gets complete and atoms achieve noble gas electronic configuration.