Roughly the big difference is:
Margin - Spacing out of content.
Padding - Spacing within content boundaries.
The styles of HTML elements are structured inside a box called "The Box Model" . Within this same box exists the hierarchy:
Element Box ( O elemento em si, div, span, entre outros )
Considering that the border of the content space of an element is its border (border box). Therefore, the big difference in this case is that the margin is already applied outside the element and will create spacing between the remaining elements, but the padding will create spacing within the element's own content, not affecting the spacing of the other elements.