CNBC's Jim Cramer knows that he constantly repeats the same old investing rules, but it's because rules mean discipline, and discipline always trumps conviction.

"One thing I've learned in my investing career: no matter how much you might believe in something, you violate the rules of the road at your own peril," the "Mad Money" host said.

Investing rules aren't easy to spot. They're not like the laws of physics, which can be deduced by observing the way the world works. The market is a beast of its own, and rules come from experience.

Cramer's nearly 40 years in the business have taught him some important lessons, lessons that he's made into rules for all the homegamers interested in buying stocks.

Some lessons he learned the hard way. At his old hedge fund, he'd occasionally convince himself that it was OK to make an exception to his rules, only to get burned in the end.

"It's like that old joke about the guy who goes to the doctor and says, 'Doctor, doctor, it hurts when I stretch out and shake my hand around,' to which the doctor replies, 'Then don't do that,'" Cramer said.

What's Cramer's No. 1 rule for investing? It might ring a bell: bulls make money, bears make money, and pigs get slaughtered.

It's not unusual to see investors in a bull market get "intoxicated with their gains," the "Mad Money" host said. But it's exactly at that point that they need to remember not to be pigs.

Cramer learned this one the hard way. When he worked at the trading desk of Michael Steinhardt's hedge fund, the legendary investor told him not to be a pig after he'd racked up a major gain.

"I had no idea what he was talking about," Cramer said. "Of course, not that long after, we got a vicious sell-off and I gave back everything I made and then some."

This is Cramer's No. 1 rule because, above all else, it helps investors stay in the game. From the 2000 dotcom bubble bust to the 2008 financial crisis, piggish buyers got slaughtered, but less greedy investors managed to cut their losses.

One of the hardest things about investing is holding on in the face of big declines or market chaos, but short-term pain often translates into long-term gains.

"Being cautious and ringing the register near tops ended up keeping you in the game," Cramer said. "Because you never know when stocks you own are going to really get crushed. You never know when the market could be just annihilated. You can't have certainty. If you assume stocks will keep going up forever in a straight line, I think you're going to be in for a world of hurt."

Rule No. 2? Don't shirk the tax man.

"Look, no one has ever liked paying taxes," the "Mad Money" host acknowledged. "But, like death, taxes are inevitable and unavoidable."

So many investors are loath to pay taxes on their winnings, but Cramer has seen some market players incur serious losses by waiting too long to write a check to Uncle Sam.

The fact is, some gains are unsustainable and should be booked quickly, no matter the cost, Cramer said. Taking some profits won't set you back dramatically; it'll keep your portfolio safe.

The bottom line? Bulls make money, bears make money, and, well, you know the rest.

"Don't be greedy," Cramer concluded. "And a variation on that theme: it's okay to pay the taxes — don't be so worried about taking a taxable profit, because you may end up with no profit at all."

WATCH: Cramer's top 2 investing rules