Expect to spend around 10-25 hours studying for the knowledge test, depending on your background.
Though you can download the study materials from the FAA for free https://www.faa.gov/regulations_policies/handbooks_manuals/aviation/media/remote_pilot_study_guide.pdf, many people find that an online course, such as https://www.goldsealdroneschool.com/uav-pilot-courses is a much more efficient method of studying for and passing the test.
There is a $150 fee for taking the test (paid to the testing company). There is no fee from the FAA.