“My bad” is an expression used when the speaker acknowledges a mistake and accepts responsibility for an error. It’s used with a minor mistake and is more of a slang term.
“I’m sorry” shows a stronger emotion of remorse and is used when the mistake might have caused someone else pain.
Person A: “The amounts on this invoice are incorrect.”
Person B: “My bad. I’ll re-do them.”
After spilling a glass of water, someone can say “my bad”
After saying something that accidentally insulted someone, it is better to say “I’m sorry.”
If you accidentally bump into some one, it’s more common to say “excuse me” or “sorry.”