The Cohen-Sutherland line clipping algorithm clips lines to a rectangular viewport by assigning region codes to line endpoints using 4 bits to represent above, below, left of, and right of the viewport. It tests the region codes of endpoints to determine if lines are fully inside, fully outside, or partially inside the viewport. If partially inside, it calculates intersection points with the viewport edges and replaces endpoints to clip the line. This efficient algorithm is commonly used in computer graphics and CAD for line clipping and cropping images.