Nitrogen generator by pressure swing adsorption is the use of a carbon molecular sieve adsorbent processed from high quality coal, coconut shell or epoxy resin under pressurized conditions, the diffusion speed of oxygen and nitrogen in the air into the carbon molecular sieve hole, so as to separate the oxygen and nitrogen in the air. Compared with nitrogen molecules, oxygen molecules first diffuse into the holes of carbon molecular sieve adsorbent, and the nitrogen that does not diffuse into the holes of carbon molecular sieve adsorbent can be used as the product output of gas for users.