We have developed a software package CALYPSO (Crystal structure AnaLYsis by Particle Swarm Optimization) to predict the energetically stable/metastable crystal structures of materials at given chemical compositions and external conditions (e.g., pressure). The CALYPSO method is based on several major techniques (e.g. particle-swarm optimization algorithm, symmetry constraints on structural generation, bond characterization matrix on elimination of similar structures, partial random structures per generation on enhancing structural diversity, and penalty function, etc) for global structural minimization from scratch. All of these techniques have been demonstrated to be critical to the prediction of global stable structure. We have implemented these techniques into the CALYPSO code. Testing of the code on many known and unknown systems shows high efficiency and high successful rate of this CALYPSO method [Wang et al., Phys. Rev. B 82 (2010) 094116]. In this paper, we focus on descriptions of the implementation of CALYPSO code and why it works.