All N2 and O2 which are commercially available are produced form of the air. Separation of compressed air is carried out into its 2 main components using membrane-type generators or using the adsorption method with variable pressure or cryogenically.

Nitrogen generation:
Membranes are suitable for lower quantities and purity. Advantage is temperature. The higher the temperature is, the higher the efficiency is. This is opposite to other production concepts.
With pressure swing adsorption (PSA) is possible to reach high purity (97 to 99.999 % of the nitrogen) and relative high production capacities. It is possible to reach even higher purity, but consumption of the compressed air is higher. The lower the purity is, the lower the nitrogen production costs are.
Cryogenic plant is the oldest concept. Pure gases can be separated from air by cooling it until it liquefies. Then components are separated based on various boiling temperatures. This concept produces high purity and high capacity gases but it is capital and energy-intensive. Cryogenic plants are typical located at the source of the consumption. Surplus of the produced gases is distributed as a liquid nitrogen or this liquid nitrogen is evaporated and compressed in high pressure cylinders.
Oxygen generation:
Compared to nitrogen there are no membranes for direct oxygen production on the market, so possible ways of the production are only PSA concept and cryogenic plant. Next to PSA we can see VPSA. V stands for vacuum. This concept differs form PSA only by operating pressure (PSA from 6 to 10 bars, VPSA about 0,5 bar). VPSA is typically used for high capacities. With PSA and VPSA it is possible to reach maximum purity 95%. Other gases are more or less noble gasses as Ar, He, etc.
With cryogenic plants, it is possible to reach higher purity, because separation is made based on different boiling points of the gases. The same as nitrogen, oxygen produced in cryogenic plants is distributed to the end costumers as a liquid or compressed oxygen.

PSA to generate Nitrogen / Oxygen:
The purified air is directed to one of two adsorption vessels that are packed with carbon molecular sieve (CMS). The impurities such as carbon dioxide and residual moisture are adsorbed by the CMS at the entrance of the adsorbent bed. When the CMS is under high pressure, it selectively adsorbs oxygen, allowing nitrogen to pass through it at the desired purity level. While one vessel is under high pressure to produce nitrogen, the second vessel is depressurized to remove the adsorbed oxygen, which is then vented into the atmosphere. Automatic switching between adsorption and desorption enables the continuous production of nitrogen. By adjusting the size of the air compressor and adsorption vessels containing the CMS it is possible to reach large range of flow and purity combinations.
Generators operates in short cycles. In one year, they can reach more than 300.000 cycles. This means that all the components of the generators must be high quality. This is especially important for valves. To achieve desired purity, it is necessary to control pressure and flow of the compressed air and also nitrogen. For correct operation, software is also important.
Compressor station with gas generation:
A typical installation of the compressor station with nitrogen or oxygen generators is shown in below schematic.

Source of the compressed air is oil lubricated screw compressor. After the compressor is air treatment stage. According to standard ISO 8573 the generators must reach class 1.4.1. This means that in compressed air particles must be smaller then 0,1 µm, pressure dew points lower than 3 °C and oil concentration in compressed air lower then 0,01 mg/m3. These criteria can be easily achieved with proper filtration and refrigeration dryer. The installation includes activated carbon tower for reducing oil. Oil reduction is reachable with filter cartridge which has an activated carbon inside. This tower actually protects the generator from oil in case of compressor failure. Due to the carbon tower, it is not possible for oil to come oil into the generator. Contamination of the generator would destroy the adsorbent. Adsorption material is very expensive, so it is cheaper to install tower with activated carbon than changing the adsorbent.
After the activated carbon tower, compressed air tank, generator and tank for nitrogen or oxygen, a particle filter which prevents dusting are installed. Generator cannot operate without vessels for nitrogen/oxygen. In case where compressed air network with compressor is much bigger as it need to be for generator, it is possible to operate without compressed air tank. In this case compressed air should also be properly treated.