How to Work with Drivers

Hi guys ...
I just wanted to know : How a software works with and uses a device through its driver installed on the OS ?!
First please let me know for what purposes a Driver is made and does it contain any libraries to use for programming ?