An encoding method comprising: a frequency domain sample sequence generation step of obtaining a sample sequence in a frequency domain deriving from an acoustic signal for each predetermined time segment; a periodicity analysis step of calculating an index indicating a degree of periodicity of the sample sequence in the frequency domain; a first encoding step of when the index represents that the periodicity is high, obtaining through loop processing, a gain code corresponding to a gain used for dividing each sample of the sample sequence in the frequency domain and an integer signal code obtained by encoding a sequence comprised of integer value samples obtained by dividing each sample of the sample sequence in the frequency domain by the gain using an encoding method based on periodicity, and otherwise, obtaining through loop processing, a gain code corresponding to a gain used for dividing each sample of the sample sequence in the frequency domain and an integer signal code obtained by encoding a sequence comprised of integer value samples obtained by dividing each sample of the sample sequence in the frequency domain by the gain using an encoding method which is not based on periodicity; a second encoding step of when the index represents that the periodicity is high, obtaining a second integer signal code obtained by encoding a sequence comprised of integer value samples obtained by dividing each sample of the sample sequence in the frequency domain by the gain corresponding to the gain code obtained in the first encoding step using an encoding method which is not based on periodicity, and otherwise, obtaining a second integer signal code obtained by encoding a sequence comprised of integer value samples obtained by dividing each sample of the sample sequence in the frequency domain by the gain corresponding to the gain code obtained in the first encoding step using an encoding method based on periodicity; and a comparison and selection step of when a code amount of the integer signal code obtained in the first encoding step is greater than a code amount of the second integer signal code obtained in the second encoding step, outputting the second integer signal code obtained in the second encoding step and the gain code, and when the code amount of the integer signal code obtained in the first encoding step is smaller than the code amount of the second integer signal code obtained in the second encoding step, outputting the integer signal code obtained in the first encoding step and the gain code. a frequency domain sample sequence generation step of obtaining a sample sequence in a frequency domain deriving from an acoustic signal for each predetermined time segment; a periodicity analysis step of calculating an index indicating a degree of periodicity of the sample sequence in the frequency domain; a first encoding step of when the index represents that the periodicity is high, obtaining through loop processing, a gain code corresponding to a gain used for dividing each sample of the sample sequence in the frequency domain and an integer signal code obtained by encoding a sequence comprised of integer value samples obtained by dividing each sample of the sample sequence in the frequency domain by the gain using an encoding method based on periodicity, and otherwise, obtaining through loop processing, a gain code corresponding to a gain used for dividing each sample of the sample sequence in the frequency domain and an integer signal code obtained by encoding a sequence comprised of integer value samples obtained by dividing each sample of the sample sequence in the frequency domain by the gain using an encoding method which is not based on periodicity; a second encoding step of when the index represents that the periodicity is high, obtaining a second integer signal code obtained by encoding a sequence comprised of integer value samples obtained by dividing each sample of the sample sequence in the frequency domain by the gain corresponding to the gain code obtained in the first encoding step using an encoding method which is not based on periodicity, and otherwise, obtaining a second integer signal code obtained by encoding a sequence comprised of integer value samples obtained by dividing each sample of the sample sequence in the frequency domain by the gain corresponding to the gain code obtained in the first encoding step using an encoding method based on periodicity; and a comparison and selection step of when a code amount of the integer signal code obtained in the first encoding step is greater than a code amount of the second integer signal code obtained in the second encoding step, outputting the second integer signal code obtained in the second encoding step and the gain code, and when the code amount of the integer signal code obtained in the first encoding step is smaller than the code amount of the second integer signal code obtained in the second encoding step, outputting the integer signal code obtained in the first encoding step and the gain code.