Although iron-based superconductors are multiorbital systems with complicated band structures, we demonstrate that the low-energy physics which is responsible for their high-T c superconductivity is essentially governed by an effective two-orbital Hamiltonian near half filling. This underlying electronic structure is protected by the S 4 symmetry. With repulsive or strong next-nearest-neighbor antiferromagnetic exchange interactions, the model results in a robust A 1g s-wave pairing which can be mapped exactly to the d-wave pairing observed in cuprates. The classification of the superconducting (SC) states according to the S 4 symmetry leads to a natural prediction of the existence of two different phases, named the A and B phases. In the B phase, the superconducting order has an overall sign change along the c axis between the top and bottom As (or Se) planes in a single Fe-As (or Fe-Se) trilayer structure, the common building block of iron-based superconductors. The sign change is analogous to the sign change in the d-wave superconducting state of cuprates upon 90 rotation. Our derivation provides a unified understanding of iron pnictides and iron chalcogenides, and suggests that cuprates and iron-based superconductors share an identical high-T c superconducting mechanism.