This paper introduces a new path planning algorithm for unmanned aerial vehicles (UAVs) based on the teaching-learning-based optimization (TLBO) technique. We first define an objective function that incorporates requirements on the path length and constraints on the movement and safe operation of UAVs to convert the path planning into an optimization problem. The optimization algorithm named Multi-subject TLBO is then proposed to minimize the formulated objective function. The algorithm is developed based on TLBO but enhanced with new operations including mutation, elite selection and multi-subject training to improve the solution quality and speed up the convergence rate. Comparison with state-of-the-art algorithms and experiments with real UAVs have been conducted to evaluate the performance of the proposed algorithm. The results confirm its validity and effectiveness in generating optimal, collision-free and flyable paths for UAVs in complex operating environments.