Day and night is caused by the rotation of the Earth about its axis. At any given time, the half facing the Sun will be shined upon while the other half will have no light. Places in the former will therefore experience day while places in the latter will experience night.
Of course, since the Earth is rotating, the illuminated places will not be illuminated forever. After some time, it will be their turn to experience night. Now, if only the Earth’s axis was perpendicular to its orbital plane, all places on Earth would experience equal times of days and nights, i.e., 12 hours of day and 12 hours of night. However, this is not so.
The Earth’s axis is actually tilted. Hence, at certain times of the year, those in the northern hemisphere will be exposed to the Sun longer than those in the southern hemisphere. Then as the Earth approaches the opposite side of its orbit, the opposite happens and those in the southern hemisphere will now have more hours under the Sun.
Subsequently, in extreme places like the North and South pole, the Sun may never set or never rise at certain times of the year.
Now, how about the Moon and stars? Why do we only see them at night? Actually, that is not entirely true. There are some days when we do see the Moon in the sky. This happens when it is somewhere in between (not necessarily directly) the Earth and Sun.
Anyway, going back to the Moon and stars question, we see the Moon and stars during the night because they’re the only ones shining in the sky. They’re still there during the day but their faint light simply cannot compete with the Sun’s bright light.
Those times of the year when the northern and southern hemispheres experience their longest days and nights are called solstices. There’s the Summer Solstice and the Winter Solstice. We’ve got articles about them here in Universe Today.
More information can be found at NASA:
Check out this podcast at Astronomy Cast: