Game of Thrones is based on A Song of Ice and Fire by George R.R. Martin.
The first five seasons roughly adapt the first five novels:
Seasons 6–8 diverged significantly as Martin had not published the next books (The Winds of Winter, A Dream of Spring), leading to original storylines and endings.