I highly recommend Computerphile's explanation of Onion Routing: https://www.youtube.com/watch?v=QRYzre4bf7I
After that, check out the video explaining how hidden services work.
If you want to see a simple implementation of an onion router, I built one in TypeScript: https://github.com/seisvelas/onion-router-ts
(be warned, I also did that as an exercise to learn more TypeScript. So it's not good TS. But improvements and issues are more than welcome from any TS gurus out there!)