This is a complex and much discussed question to which there are many varying opinions. The generally accepted difference between Rap and Hip Hop is that Rap evolved from Hip Hop. Hip Hop began in the 1960’s and 1970’s in New York when pioneer artist D.J. Kool Herc isolated the percussion in funk, rock and latin beats and mixed it in various ways. Really, Hip Hop evolved from Funk artitsts like James Brown. Rap came about as MC’s created fast talking, rhyming introductions and interludes to DJ’s performances. Rap then took on a life of its own.
Rap, a style of music associated with rapid talking in rhymes to a beat accompanyment, also takes some of its roots from the Beat Poetry of the 1960’s; focussing on the social and political climate of the time. The first big Rap song hit the charts in 1979 with Sugar Hill Gang’s Rapper’s Delight.
If we were looking at Rap and Hip Hop belonging to a family tree, at the very top would be D.J. Kool Herc with his two children being Rap and Hip Hop (obviously with much overlap), related, but separate and distinct.