How do you access more memory (above the 1 MB) in DOS if the 640 KB of conventional memory are not enough?

I have read a lot about this, but I couldn't figure out how to do this in actual code. Is there an API for this (like in HIMEM.SYS), or can I code it myself? Any answer is fine, whether it uses the XMS or the EMS standard or manually written code. From what I read, though, EMS requires specialized hardware, which is not very convenient.

If you can, please also explain if there are any differences between doing it on an [Intel 80286][1] or an [Intel 80386][2]. Does it necessarily require switching to [protected mode][3]?

 [1]: https://en.wikipedia.org/wiki/Intel_80286
 [2]: https://en.wikipedia.org/wiki/Intel_80386
 [3]: https://en.wikipedia.org/wiki/Protected_mode