An encoding method of speech or acoustic signals comprising acquiring codes corresponding to prediction residuals obtained according to prediction analysis applied to time series signals included in a plurality of predetermined time intervals of input time series signals, with the number of bits to be assigned to the codes corresponding to the prediction residuals being switched according to whether an index that indicates a level of periodicity and/or stationarity corresponding to time series signals in the respective predetermined time intervals or time series signals in an interval before the respective predetermined time intervals of the input time series signals satisfies a condition that indicates high periodicity and/or high stationarity or a condition that indicates low periodicity and/or low stationarity, wherein the number of bits of the codes corresponding to the prediction residuals, obtained when the index that indicates the level of periodicity and/or stationarity satisfies the condition that indicates high periodicity and/or high stationarity, is smaller than the number of bits of the codes corresponding to the prediction residuals, obtained when the index that indicates the level of periodicity and/or stationarity does not satisfy the condition that indicates high periodicity and/or high stationarity; or the number of bits of the codes corresponding to the prediction residuals, obtained when the index that indicates the level of periodicity and/or stationarity satisfies the condition that indicates low periodicity and/or low stationarity, is larger than the number of bits of the codes corresponding to the prediction residuals, obtained when the index that indicates the level of periodicity and/or stationarity does not satisfy the condition that indicates low periodicity and/or low stationarity, characterized in that: a predetermined total number of bits is assigned to codes corresponding to a time interval that consists of the predetermined time intervals and a second predetermined time interval after the predetermined time intervals, wherein the second predetermined time interval is a last subinterval of the time interval; and the number of bits to be assigned to codes corresponding to second prediction residuals obtained according to prediction analysis applied to time series signals included in the second predetermined time interval is determined according to the number of unassigned bits determined from the total number of bits and the number of bits to be assigned to the codes corresponding to the prediction residuals obtained according to the prediction analysis applied to the time series signals included in the predetermined time intervals, to acquire the codes, with the determined number of bits, corresponding to the second prediction residuals. a predetermined total number of bits is assigned to codes corresponding to a time interval that consists of the predetermined time intervals and a second predetermined time interval after the predetermined time intervals, wherein the second predetermined time interval is a last subinterval of the time interval; and the number of bits to be assigned to codes corresponding to second prediction residuals obtained according to prediction analysis applied to time series signals included in the second predetermined time interval is determined according to the number of unassigned bits determined from the total number of bits and the number of bits to be assigned to the codes corresponding to the prediction residuals obtained according to the prediction analysis applied to the time series signals included in the predetermined time intervals, to acquire the codes, with the determined number of bits, corresponding to the second prediction residuals.