The nostrils are an evolutionary relic of our fish ancestry.
Fish nostrils have nothing to do with breathing. In most species, they are used only for smelling and don’t even connect to the respiratory system. So our fish ancestors had 4 nostrils: 2 forward nostrils through which water entered, and two rear nostrils through which it exited. The passages between fore and aft contained the olfactory organs.
At some point in our evolution, the rear nostrils got moved inward and became the choanae, where the two nasal passages join at the very top of the throat. From there all the air travels down a single passage, the trachea, until it branches again to the two lungs (each lung does not have its own nostril).
If you look at our evolutionary history, you could say that the mouth is one big breathing aperture. It just so happened that the nasal passages ended up also feeding into that system. As far as breathing goes, we can really do pretty well without any nostrils at all, which is why we don’t die when we get colds.
Since the nostrils evolved primarily as smelling apertures, there might be some advantage to having two of them in animals, like fish, that depend heavily on smell. Just as having two ears and two eyes provides useful spacial information about stimuli, maybe the difference in the sensation of the two nostrils on either side of a fish’s head conveys some subtle sense of direction or proximity.