Why does Lent last 40 days?
Forty is a standard Biblical number meaning a long time, like the Hebrews' 40 years in the wilderness after the exodus, and Jesus' 40 days in the wilderness after his baptism. Those examples suggest a time of preparation. The wilderness wandering prepared the Hebrews to enter the promised land of Canaan. Jesus' time in the wilderness prepared him for a ministry as Messiah. Lent, then, was one of the Church's two seasons of preparation for baptism. The other was the season of Advent, which originally was 40 days leading up to Epiphany.
Lent traditionally ends with the sacrament of baptism on Easter Eve or on Easter Morning. The original aim was to use the 40 days for intensive preparation of candidates for baptism.