Corrosion is a random phenomenon which reduces the strength of pipeline systems over time. Continuous operation of such systems involves significant expenditures in inspection and maintenance. The cost- effective safety management of pipeline systems involves finding the appropriate amount of resources to allocate to initial design and to inspection and maintenance activities, in order to keep expected costs of failure (risk) under control. This article addresses the optimal inspection planning for onshore pipelines subject to external corrosion. The investigation combines a stochastic model of corrosion growth with limit state functions describing leak, burst or rupture of a pipeline segment containing corrosion defects. Uncertainties of inspection results are also taken into account. The objective function is obtained by adding initial costs, cost of inspections and the expected costs of repair and failure. The expected numbers of failures and repairs are evaluated by Monte Carlo simulation. Optimum inspection intervals are found for an example problem.