Ultramicroporous semicycloaliphatic polyimides with major pore sizes less than 0.5 nm are synthesized through imidization reaction between different aromatic tetraamines and cycloaliphatic dianhydrides. The synergistic role of abundant CO2-philic imide rings and the molecular sieving effect of ultrasmall pores in the polyimide network bring about high adsorption selectivity of CO2/CH4 (37.2) and CO2/N2 (136.7). In addition, it is interesting to observe that, under ambient condition (298 K/1 bar), n-butane exhibits the highest uptake (3.15 mmol/g) among the C1-C4 alkanes, and the adsorbed amount significantly drops with the reduction of the number of carbon atoms. As a result, the mixed light alkanes can be effectively separated according to the carbon numbers. The separation factors of n-butane/propane and propane/ethane reach 3.1 and 6.5, whereas those of n-butane, propane, and ethane over methane are as high as 414.5, 217.4, and 19.6, respectively. Moreover, the polyimides display large adsorption capacities for 1,3-butadiene (4.64 mmol/g) and propene (2.68 mmol/g) with good selectivity over 1-butene and propane of 3.2 and 3.0, respectively. Together with the excellent thermal and physicochemical stabilities, the ultramicroporous polyimides obtained in this work show promising applications in adsorption/separation for CO2, CH4, and C2-C4 hydrocarbons.