Codecs are programs that encode data as usable files, whether images, audio or video. Compression codecs are designed to remove data without losing quality (where possible). Algorithms work out what data can be removed and reduce file size.
One of the simplest examples of compression is RLE. RLE is a basic form of data compression that converts consecutive identical values into a code consisting of the character and the number marking the length of the run. The more similar values there are, the more values can be compressed. The sequence of data is stored as a single value and count.
For example, for a minute of a scene filmed at a beach there would be similar colours on screen for the duration of the shot, such as the blues of the sky and the sea, and the yellows of the sand. Each frame would contain similar data so the file doesn't need to record all the colours each time. Compression software understands that it's seeing the same colours over and over again so it can recycle some of the data it has captured before, rather than storing every detail of every frame.