When sunlight hits the Earth's atmosphere, it interacts with molecules of nitrogen, oxygen, and other gases. The molecules scatter the sunlight in all directions, but the blue light is scattered more than other colors. This is because blue light has a shorter wavelength than other colors and is more likely to be scattered by the gas molecules.
As a result, more blue light reaches our eyes from all directions, making the Earth look blue from outer space.