For the security problem of existing schemes in the image encryption, and the problem of low compression due to poor coding, this paper proposes a reversible data hiding algorithm of image encryption based on prediction error adaptive coding. In the image encryption stage, an image encryption algorithm based on error maintenance is designed. First, block scrambling and pixel modulation encryption are performed on 3×3 image blocks, and then non-center pixels are grouped and scrambled according to the central pixel value of the image block. In the data embedding stage, adaptive coding is based on the prediction error distribution of the image, after marking and classifying the pixels with the coding table, and the coding table and additional data are hidden together in the encrypted image to generate a marked encrypted image. The experimental results show that group scrambling operation in the encryption phase increases the number of eigenvalue difference blocks between the original image and the encrypted image, makes it difficult to determine the correspondence between the image blocks in the image before and after encryption, improves the security of the encrypted image, and keeps the overall prediction error distribution of the image. Compared with state-of-the-art algorithms, the average embedding rate can be improved by more than 0.49bpp, the additional data can be extracted losslessly and the original image can be restored.