For taking full advantage of carrier image's pixel correlation, a lossless data hiding algorithm with ranks transform (LDHA_RT) is proposed. Along with three directions of column, row and diagonal, the pixel difference images and their histograms are calculated one after another. The obtained pixel difference histograms are shifted to construct the redundancy spaces, so that the hiding information could be embedded in a designated position. After the hiding data is extracted, the carrier image could be recovered reversibly without any additional information. The experiments demonstrate that the PSNR/bits of the LDHA_RT is the lowest or close to the lowest, compard with these algorithms mentioned in the references. This implies that the LDHA_RT has large capacity of hiding data under a good image quality.