Broken rails are the most frequent cause of freight-train derailments in the United States. Consequently, reducing their occurrence is a high priority for the rail industry and the U.S. Federal Railroad Administration. Current practice is to periodically inspect rails to detect defects using nondestructive technology such as ultrasonic inspection. Determining the optimal rail inspection frequency is critical to efficient use of infrastructure management resources and maximizing the beneficial impact on safety. Minimization of derailment risk, costs of inspection vehicle operation, rail defect repair, and corresponding train delay are all affected by rail inspection frequency. However, no prior research has incorporated all of these factors into a single integrated framework. The objective of this paper is to develop an analytical model to address the trade-offs among various factors related to rail defect inspection frequency, so as to maximize railroad safety and efficiency. The analysis shows that the optimal inspection frequency will vary with traffic density, rail age, inspection technology reliability, and other factors. The optimization model provides a tool that can be used to aid development of better-informed, more effective infrastructure management and accident prevention policies and practices.