Due to their broad application to different fields of theory and practice, generalized Petersen graphs GP G(n, s) have been extensively investigated. Despite the regularity of generalized Petersen graphs, determining an exact formula for the diameter is still a difficult problem. In their paper, Beenker and Van Lint have proved that if the circulant graph C n (1, s) has diameter d, then GP G(n, s) has diameter at least d + 1 and at most d + 2. In this paper, we provide necessary and sufficient conditions so that the diameter of GP G(n, s) is equal to d+ 1, and sufficient conditions so that the diameter of GP G(n, s) is equal to d + 2. Afterwards, we give exact values for the diameter of GP G(n, s) for almost all cases of n and s. Furthermore, we show that there exists an algorithm computing the diameter of generalized Petersen graphs with running time O(logn).Keywords Diameter • Generalized Petersen graphs • Circulant graphs, • Edge-contraction s gcd(n,s) , the paths P 1 c (i), P 2 c (i), P 1,t c (i), P 2,t c (i), P 3,t c (i), P 4,t c (i) are pairwise nonequivalent and walk through outer edges before entering to inner edges.