Trailing oil is the tail section of contamination in oil pipelines. It is generated in batch transportation, for which one fluid, such as diesel oil follows another fluid, such as gasoline, and it has an effect on the quality of oil. This paper describes our analysis of the formation mechanism of trailing oil in pipelines and our study of the influence of dead-legs on the formation of trailing oil. We found that the oil replacement rate in a dead-leg is exponentially related to the flow speed, and the length of the dead-leg is exponentially related to the replacement time of the oil. To reduce the amount of mixed oil, the main flow speed should be kept at about 1.6 m/s, and the length of the dead-leg should be less than five times the diameter of the main pipe. In our work, the Reynolds time-averaged method is used to simulate turbulence. To obtain contamination-related experimental data, computational fluid dynamics (CFD) software is used to simulate different flow rates and bypass lengths. MATLAB software was used to perform multi-nonlinear regression for the oil substitution time, the length of the bypass, and the flow speed. We determined an equation for calculating the length of the trailing oil contamination produced by the dead-leg. A modified equation for calculating the length of the contamination was obtained by combining the existing equation for calculating the length of the contamination with new factors based on our work. The amounts of contamination predicted by the new equation is closer to the actual contamination amounts than predicted values from other methods suggested by previous scholars.