The summer solstice, which falls on June 21 in the Northern Hemisphere, offers more total sunlight than any other day of the year. It would seem to make sense, then, for the summer solstice to also feature the year's earliest sunrise and latest sunset.
Many people are surprised, however, to learn that isn't quite how it works. While the solstice offers the greatest amount of daylight overall, the earliest sunrise occurs before the solstice and the latest sunset falls afterward. The exact dates vary by latitude, with the year's earliest sunrise and latest sunset occurring further from the solstice date the closer you are to the equator.
In Hawaii, for example, the earliest sunset is about two weeks before the summer solstice, and the latest sunset comes about two weeks after, as astronomy writer Bruce McClure explains for EarthSky. At the Northern Hemisphere's mid-northern latitudes, on the other hand, the earliest sunrise will take place June 14 and the latest sunset will follow on June 27.
If you're in the Southern Hemisphere, the June solstice is the shortest day of the year, and it's similarly bookended by the latest sunrise and earliest sunset. A city at 40 degrees north latitude (like Philadelphia) will see its earliest sunrise at 5:31 a.m. on June 14, for instance, while a city at 40 degrees south latitude (like Valdivia, Chile) will see its latest sunrise at 8:12 a.m. on the same day.
This is largely due to the tilt of Earth's rotational axis, as astronomer Ken Croswell explains in StarDate magazine, but it's also influenced by our elliptical orbit around the sun, which causes Earth to travel at different speeds throughout the year.
For a more in-depth explanation, see this breakdown of the phenomenon from the U.S. Naval Observatory (USNO). And to find out when the sun will rise and set where you are, check out this calculator from the USNO's Astronomical Applications Department.