A mattress affects sleep by either promoting or hindering spinal alignment, influencing sleep quality through comfort and support, and potentially causing or alleviating pain. The right mattress can lead to deeper, more restorative sleep, while the wrong one can led to discomfort and sleep disturbances.