Thermal optimization of pulsating heat pipes (PHPs) is conducted with a numerical approach. A one-dimensional numerical model based on the assumption of slug/plug flow is developed for predicting the thermal performance of a pulsating heat pipe. Thermal interaction between the solid wall and oscillating liquid slugs/vapor plugs is included in the model. Both the thickness and the length of the liquid films enclosing vapor plugs can vary during evaporation or condensation, so the proposed model can predict the thermal performance without employing any adjustable variables with regard to the liquid film thickness. The developed model is validated by the experimental data available in literature. Finally, under the constraint of fixed space, thermal performance optimization in a vertical orientation is performed in terms of the channel diameter and the number of turns. It is found that there exists an optimum number of turns or an optimum channel diameter. A merit number for finding the optimum number of turns under the constraint of fixed space is numerically proposed. The proposed merit number provides a design guideline for a pulsating heat pipe: the thermal performance of a pulsating heat pipe is optimized when the merit number is maximized.