An intelligent optimization of multistage gas permeation layouts is required to achieve high product gas purities and high product recoveries at the same time in gas separation technologies. In this work, a superstructure-based mathematical model for the optimization of CO2 removal in three applications including post-combustion CO2 capture, natural gas sweetening and biogas upgrading is designed. A typical polymeric membrane prepared within the BIOCOMEM project, with high CO2 permeance, CO2/N2 selectivity of 25, and CO2/CH4 selectivity of 7.9 is studied to assess the potential of this membrane at a real industrial scale. Using a superstructure-based model, operating conditions, driving force distribution along each membrane stage, the use of feed compression and/or permeate vacuum, the number of stages and recycle options are simultaneously optimized. The techno-economic analysis of all three applications is then carried out and the most promising membrane-based process configuration was chosen. The multi-stage membrane process is investigated in terms of capture cost, energy consumption, and membrane area. The results revealed that high purity and recovery at a minimum cost could be achieved by the three-stage process in post-combustion CO2 capture and natural gas while in biogas upgrading the two-stage configuration exhibited the best performance. It was found that a reduction in capture cost to around 42 €/tCO2 is possible in post-combustion CO2 capture if membranes with a selectivity of 50 and the same permeation flow are developed.