Both are of Latin origin.

i.e. stands for "id est" which means "that is" or "which is to say" and is used for clarification. "Jeff couldn't read the book, i.e., he's illiterate".

e.g. means "exempli gratia" and is used synonymously with "for example". "Jeff is doing a lot to learn how to read, e.g., he's taking classes".

Commas are always placed before and after i.e and e.g.