How does background-size: cover and contain work?

How does background-size: cover and contain work ? I want to understand how cover and contain works when a background-image is applied, like what happens to the image pixels so that they can fill/fit the background of the element

You can read about background-size here: