Buddhists believe in something called “karma”.
Karma simply means “cause and effect”, in the Buddhist sense.
Every action you take has an effect, and those effects cause other effects (think: billiard balls striking one another).
There is no “good” karma and “bad” karma.
There is merely the net effect of all the things you have set into motion.
This translates into things that often appear good or bad.
For example: if you beat your son, he’s likely to hurt others in the future. You aren’t directly hurting anyone but your son, but the net effect of your actions could be causing harm to others, who in turn hurt others even more.
The same is true when you do “good” things. Help one person pay their rent this month, and now they are able to feed their kids, those kids see how their mom struggled, and how a stranger helped just when she needed it most, and they go on to help others some day, etc.
Now what this has to do with reincarnation first requires you to understand that the Buddhist concept is not the same as the Hindu belief of the same name. When you die and are “reborn” in the Buddhist sense, it’s not some mystical soul that travels from body to body.
It’s your karma that experiences rebirth.
The effect of everything you’ve done in your life ripples out from you and continues to bounce around long after you are gone. Eventually the long chain of events that you set into motion will arrive at the place and time where a new creature is born.
If you’ve done lots of good things, then the chain of events you set in motion will be passing through people mostly having good lives, so when your karma all meets up to cause two people to make a baby, you’ll be “reborn” into a pretty good situation.
Likewise if you are a horrible person, the things you do will mostly have an effect on miserable people, and you’ll be reborn in a bad situation.
That’s essentially how it works.
If course the goal of Buddhism isn’t to be reborn in better situations. It’s to never be reborn at all. Buddhism is about escaping the endless cycle of death and rebirth permanently by attaining “Nirvana”.
Nirvana literally means “blowing out”, like a candle. It’s the state where you no longer are part of the chain of cause and effect, the ultimate freedom, but also the ultimate end of the ego.
[Source:] Edited from the comment from gnovos on Reddit for posterity.