The subject of a book or story is what it is about. In a fictional work, the subject is called the plot. It is what happens: Miss Marple finds a dead body in the parlor, then the police come, then Mr. Brown is arrested, and so on. In a nonfiction work, the subject again is what the book is about in a factual way. It is the sequence of events that unfold: a man goes with his family to Berlin to be ambassador in 1933 and meets Adolph Hitler, etc. The subject of a book answers the what question: what happened first, second, third, etc.
The theme is the message or meaning the work is trying to communicate. It is the why question. Why did the writer write it? What is the underlying point the author is trying to make? For example, a fiction writer of a murder mystery may be trying to send the message that appearances are deceiving and that we should think carefully and explore more deeply before we jump to the conclusion someone is a murderer. The non-fiction writer of the history of the ambassador to Berlin in an extraordinary period of history might be trying to communicate the sense of psychological stress and unease that even privileged people experienced living in a regime based on surveillance and terror. That would be the message or theme that would stick with you long after specific facts faded.
Even books that seem to have no theme almost always communicate a message. A book about how a chicken lays an egg and how it hatches may seem simply an informational work for a young child, but it fact it communicates deeper themes or messages, such as that the world is a safe and orderly place in which natural events proceed in a knowable way.