Gamma-ray spectroscopy is an essential technique for identifying the composition of radioactive materials. This work presents a detailed algorithm for analysing gamma-ray spectra, focusing on peak detection, energy calibration, efficiency calibration and nuclide identification. The algorithm includes a systematic approach to match observed peaks with known nuclides, following a peak detection method, efficiency and energy calibration methods. The algorithm attempts to provide spectral analysis and nuclides identification on-site with portable spectroscopic devices. Therefore, it is tested with portable HPGe and CZT detectors demonstrating its ability to reliably identify isotopes in complex spectra, derived by multi radioactive sources identification scenarios. A conventional energy calibration is performed on the spectrum data to convert channels to energy values. Additional calibration is performed to adjust the height of the photopeaks, considering the efficiency curve of each detector. The algorithm identifies possible nuclides associated with each peak by searching for nuclides within a specified range of energy interval, minimum half-life, and minimum fraction yield of the photopeak. The matching process involves comparing photopeaks of the spectrum under investigation with a complete dataset of energies of γ-rays and their emitters. To exclude false positive identifications of nuclides, a criterion considers a certain number of the most intense γ-ray energies that each possible nuclide emits and investigates whether these energies are correlated with the photopeaks. In addition, another criterion checks the height of the photopeaks based on their fraction yield. The algorithm attempts to offer a solution for field applications, enhancing radiological crime-scene investigations and environmental monitoring.