Microporous materials have a great importance in catalysis, delivery, storage and separation in terms of their performance and efficiency. Most microporous materials are comprised of inorganic frameworks, while thermally rearranged (TR) polymers are a microporous organic polymer which is tuned to optimize the cavity sizes and distribution for difficult separation applications. The sub-nano sized microcavities are controlled by in situ thermal treatment conditions which have been investigated by positron annihilation lifetime spectroscopy (PALS). The size and relative number of cavities increased from room temperature to 230 °C resulting in improvements in both permeabilities and selectivities for H2/CO2 separation due to the significant increase of gas diffusion and decrease of CO2 solubility. The highest performance of the well-tuned TR-polymer membrane was 206 Barrer for H2 permeability and 6.2 of H2/CO2 selectivity, exceeding the polymeric upper bound for gas separation membranes.