A good portion of it is just pure chance. There are relatively few people patrolling new submissions, and if something doesn't get a couple of upvotes in the first hour or so, it just disappears down the memory hole. So, you'll sometimes lose even if your content is good.
Another part of the equation is topic and tone. There's no sophisticated algorithm, but it's an eclectic forum, so if your post sounds like pure marketing or self-promo, it will probably not make it far. You need to offer something of value to readers, not to you.
An interesting quirk of the system is that people who upvote or comment on stories don't necessarily read them. A lot of HN discussion boils down to people reacting to the prompt in the subject line. There are publications that learned how to game this. I don't think it's a template worth following, but it sells...