In this paper, an optimal multilevel stack filtering algorithm (the stack filters used at each level are designed to be optimal) is introduced. Optimal multilevel stack filter is capable of considering a larger window mask than an optimal stack filter. Multilevel unidirectional stack filters and multilevel bidirectional stack filters are studied in particular. Design of an optimal multilevel stack filter is similar to the design of an optimal stack filter where the compare-and- select algorithm can be used. However, the design procedure needs to be adapted to operation on more than one level. Several design examples are presented showing the good performance of the proposed method.