Nature-inspired algorithms allow us to solve many problems related to the search for optimal solutions. One such issue is the problem of searching for optimal routes. In this paper, ant colony optimization is used to search for optimal tram routes. Ant colony optimization is a method inspired by the behavior of ants in nature, which as a group are able to successfully find optimal routes from the nest to food. The aim of this paper is to present a practical application of the algorithm as a tool for public transport network planning. In urban public transport, travel time is crucial. It is a major factor in passengers’ choice of transport mode. Therefore, in this paper, the objective function determining the operation of the algorithm is driving time. Scheduled time, real time and theoretical time are analyzed and compared. The routes are then compared with each other in order to select the optimal solution. A case study involving one of the largest tramway networks in Poland demonstrates the effectiveness of the nature-inspired algorithm. The obtained results allow route optimization by selecting the route with the shortest travel time. Thus, the development of the entire network is also possible. In addition, due to its versatility, the method can be applied to various modes of transport.