The stellarator optimization leading to the physics design of Wendelstein 7-X (W7-X) is reviewed. The need for stellarator optimization is exemplified. A strategy of optimization as well as the structure of the optimization space are described. Results pertaining to W7-X are given. Investigations with advanced tools and perspectives for advanced physics features – such as the structure of the magnetic surfaces at finite β, the structure of unstable modes, elements of anomalous transport and divertor considerations – are indicated.