"I" and "me" are both personal pronouns. A personal pronoun is a word that can substitute for a noun and that represents a person. Confusion over usage comes about because English distinguishes between object pronouns and subject pronouns, even though it treats nouns the same way whether they are subjects or objects of a sentence.
Basic distinction between "I" and "me"
"I" is a subject pronoun, and "me" is an object pronoun (pronouns are also said to be in subjective or objective case). The subject of a sentence is the thing doing an action. So in the sentence "John runs to Mary," John is the subject because he is doing the running. The object of a sentence is the thing not doing something but being acted upon. In the sentence, Mary is an object for that reason.
Use "Me" for Objects and "I" for Subjects
In the sentence in section 1, John would say, "I ran to Mary," but Mary would say, "John ran to me." Often (but not always) the object of a sentence has a preposition before it; in this sentence the preposition is "to." If you were John, you could also say, "I ran a race." In that sentence, "race" is called the direct object.
Use "I" for State-of-Being Verbs
A state-of-being verb expresses existence; the most common such verb is "to be," which has many forms. Thus it is correct to say "It is I," though that sounds incorrect to many. Applying the rule may make you sound fussy or too formal. Many people say "It is me."
The statement sounds odd because the usual order of English sentences is subject, verb, object. One way to avoid the problem of "it is I" versus "it is me" is to change the sentence order, putting the subject first and saying "I am."
Use "Me" When You Have a Preposition in Front of the Pronoun
In addition to distinguishing subjects and objects by whether they act or are acted upon, you can spot objects if they have prepositions before them. Prepositions are words like "on," "under" or "around" and express a relationship between two things. Not all objects have prepositions, but no subjects do. For example, "John gave Mary the ball" has no preposition but is equivalent to "John gave the ball to Mary." Mary is an object in both sentences --- in the first the indirect object and in the second the object of a preposition. Thus if you were John (the subject), you would write, "I gave Mary the ball." If you were Mary, you would write, "John gave me the ball," with "me" being the indirect object.