It is a common principle that aeration to a wastewater treatment reactor performing aerobic carbon and ammonium oxidation should be minimised while satisfactory carbon and ammonium removal is achieved. The implementation of this principle in a plug-flow like aerobic reactor has so far been in an ad-hoc manner in the absence of a theoretically optimal dissolved oxygen (DO) profile. In this study, the Pontryagin Maximum Principle is applied to derive the theoretically optimal DO profile along a plugflow aerobic reactor. While it is difficult to implement this optimisation algorithm online in practice due to the requirement of detailed wastewater composition and model parameter information, the optimal aeration profiles revealed under various conditions provide guidance to the design and operation of aeration systems. The optimal K L a and DO profiles can be applied in benchmark model to not only achieve satisfactory effluent requirements but also aeration energy is saved.