This paper refers to nitrogen removal optimization of an alternating oxidation ditch system through the use of a mathematical model and pilot testing. The pilot system where measurements have been made has a total volume of 120 m(3) and consists of two ditches operating in four phases during one cycle and performs carbon oxidation, nitrification, denitrification and settling. The mathematical model consists of one-dimensional mass balance (convection-dispersion) equations based on the IAWPRC ASM 1 model. After the calibration and verification of the model, simulation system performance was made. Optimization is achieved by testing operational cycles and phases with different time lengths. The limits of EU directive 91/271 for nitrogen removal have been used for comparison. The findings show that operational cycles with smaller time lengths can achieve higher nitrogen removals and that an "equilibrium" between phase time percentages in the whole cycle, for a given inflow, must be achieved.