In an embodiment, an encoding method includes generating a histogram corresponding to all pixels in a coding unit. The encoding method further includes seeking a first color value according to the histogram, wherein a first number of pixels of the first color value in the histogram is greater than or equals to a first threshold. The encoding method further includes seeking a second color value in a first range of the first color value according to the histogram. The encoding method further includes removing one or more pixels of the first color value from the histogram when a second number of pixels of the second color value is greater than or equals to a second threshold. The encoding method further includes adding the first color value into an initial color table when the second number of pixels is less than the second threshold. An encoder is also provided in the disclosure.