Question: When is it correct to use *no* and *nope*? Is there any difference between them?

Answer: 
Any difference? Nope - not in meaning anyway. 

Actually, "nope" means "no," but only in the sense of the opposite of "yes." Therefore, you might use it to answer a yes-or-no question in the negative, but you would **never** say, "*We found nope errors during the inspection*," or "*There was nope way Dave would ever surrender*."

That said, "nope" is informal, and should only be used in writing in the most informal of contexts.
J.R. is correct to note that *nope* occurs only as a one-word answer to Y/N questions, and not for other uses of *no*.

The final "pe" in *nope* comes from the way it is pronounced, ending with **firmly** closed lips to signal the end of the word, answer, utterance, and discussion. 

The "p" part is produced by closing the lips, and the silent "e" comes from the English spelling system, which requires it there to keep the pronunciation of "o" as tense /o/ even though it's followed by (what sounds like) a consonant. 

Similar reasons account for *yup* as a variant of *ya ~ yeah*, which needs no final "e" because the vowel is not tense.