In summary, the utilization of Legendre polynomial expansion in the modal analysis of stratified dielectric layers with doubly periodic permittivity profiles offers a departure from conventional methods. This novel approach, grounded in the analytical projection of Maxwell’s equations onto the Hilbert space defined by Legendre polynomials, results in well-behaved algebraic equations. These equations, in turn, facilitate the derivation of propagation constants and electromagnetic field profiles, circumventing issues related to numerical instability and oscillatory behavior. Moreover, the method's adaptability to extend its application to nonperiodic dielectric waveguides through the periodic repetition concept further underscores its versatility and potential impact in electromagnetic field analysis. Finally, to validate the proposed method, we conducted a comparative analysis of three standard test cases against previously reported results in the literature. The comparison showcased a high level of agreement, affirming the accuracy and efficacy of the presented approach.