From Sahih Bukhari (Hadith 3851):
Narrated Ibn `Abbas:Allah's Messenger (ﷺ) was inspired Divinely at the age of forty. Then he stayed in Mecca for thirteen years, and then was ordered to migrate, and he migrated to Medina and stayed there for ten years and then died
Reference: Bukhari 3851