Abstract This paper introduces a new method for creating an all-optical AND gate by utilizing a two-dimensional photonic crystal configuration for the first time. This gate design is intended for applications in optical computing and all-optical logic, offering the potential for rapid computation and parallel processing. The described gate is characterized by its compact dimensions and comprises two inputs and a single output. The high and low logic states are defined based on power values, where logic 0 corresponds to low power and logic 1 corresponds to high power emitted from the light source. To enhance the design process, artificial neural networks (ANNs) are utilized. ANNs offer a powerful tool for optimizing and fine-tuning the photonic crystal structure parameters to achieve the desired logic functionality. With the help of the applied ANNs, the design process is eased and high performance is achieved for the proposed photonic crystal structure. By integrating ANNs into the design process, this research opens up new possibilities for advancing the field of photonic logic circuits. Combining photonic crystals and ANN optimization provides a powerful approach to designing complex and efficient optical computing systems. The results show that the obtained power values are high for 1 logic state and low for the 0 logic state, which verifies the AND gate accuracy table. The achieved accurate results verify the validity of the proposed approach for achieving precise and reliable all-optical logic operations.