Topology optimization (TopOpt) methods for inverse design of nano-photonic systems have recently become extremely popular and are presented in various forms and under various names. Approaches comprise gradientand non-gradient-based algorithms combined with more or less systematic ways to improve convergence, discreteness of solutions, and satisfaction of manufacturing constraints.We here provide a tutorial for the systematic and efficient design of nano-photonic structures by TopOpt. The implementation is based on the advanced and systematic approaches developed in TopOpt for structural optimization during the last three decades. The tutorial presents a step-by-step guide for deriving the continuous constrained optimization problem forming the foundation of the TopOpt method, using a cylindrical metalens design problem as an example. It demonstrates the effect and necessity of applying a number of auxiliary tools in the design process to ensure good numerical modeling practice and to achieve physically realizable designs. Application examples also include an optical demultiplexer.