The phenomenon you're referring to is called day and night, and it occurs due to the rotation of the Earth on its axis. The Earth takes approximately 24 hours to complete one full rotation. As it rotates, different parts of the Earth receive varying amounts of sunlight, leading to the distinction between day and night.
When a specific region on Earth is facing towards the Sun, it is in daylight because it is directly exposed to the Sun's rays. The Sun illuminates that side of the Earth, providing light and warmth. Meanwhile, the opposite side of the Earth, which is facing away from the Sun, experiences darkness. This area is shielded from the direct sunlight, resulting in nighttime.
The Earth's rotation causes the transition between day and night as different regions move in and out of the sunlight. As the Earth continues to rotate, the boundary between daylight and darkness progresses across the planet, creating a cycle of day and night for different regions.
The tilt of the Earth's axis also plays a significant role in the changing length of daylight throughout the year in different regions. This is why we experience seasons as the tilt affects the angle at which sunlight reaches specific parts of the Earth during different times of the year.