Confidence is a person that doesn't feel the need to show they're confident. They feel good about themselves, or their particular ability and don't need to showboat it.
Cocky people want to be seen. Recognized. Admired. Showoffs basically. Which is rooted in insecurity because they don't truly believe in themselves. And even when they have skills they excel at they still need external validation, only to use that validation to turn around and put people down for not being as good.
One example of this i saw was in an MMA fight. The first fighter came out like a walking slab of muscle, totally ripped and a monster. He was brash, cocky, attention needing, showing off, trying to look tough.
The other fighter comes out looking like he spent more times in bars than gyms. He was tall, but not very muscular and despite a slim figure had a beer gut. He strolled out without any hype. No stare downs. No playing up to the crowd. He could've just as easily been going for a walk as going into the ring. He was calm.
Fight starts, tough guy charges fast and catches the other guy off guard, but he recovers quickly. Gets his focus and dominates the tough guy in the next 20 seconds. The whole match was about 30 seconds and the cocky guy got his clock cleaned by a guy who Knew he was good without trying to prove anything to anyone but his opponent.
Anytime i hear the cocky vs confident question this match always comes to mind.