With $28,000 in student loan debt when he graduated from college last spring, Patrick O'Keefe took a step that not many students would take when looking to get out of debt: He signed up for a 30-year mortgage to buy a house.

Earning a good annual salary of $52,000, O'Keefe qualified for a loan to buy a $154,900 house in Baltimore, Maryland, by lowering his debt-to-income ratio through an unusual but smart decision, according to mortgage experts - going to graduate school, which allows a student to defer paying student loans and doesn't count as debt when applying for a home loan.

O'Keefe, 22, also made other smart decisions, including cutting expenses, getting a co-signer for the mortgage loan, having a steady job and plans to start making some student loan payments soon.

Here's a look at what he did, along with five tips on how to prepare for buying a home when you have student loan debt:

1 - Have low debt

Banks will look at any debt that is for 10 months or more, such as credit card, car and alimony payments, says Joe Parsons, a senior loan officer at PFS Funding, a mortgage banker in Dublin, CA. A low debt-to-income ratio - which is basically debt divided by income and can be done on an online calculator - should be no more than 50% for a conventional loan and 55% for an FHA loan, Parsons says.

To unload some debt, students shouldn't have a car loan and should instead buy a car they can afford, he says. They should also pay off any credit card debt if they can, he says.

O'Keefe already lives frugally and leases a car, cutting his consumer debt considerably.

2 - Have income

Having a job to pay for a mortgage goes without saying, but loan applicants should be sure to list all of the income beyond a stable salary, Parsons says. that includes rental income, alimony received and child support.

In the year O'Keefe has been working as a marketing sales associate, he's received promotions and raises, and is in a stable job. "I think I'm in a good situation, considering the circumstances because each job I've had I've saved up pretty well," he says.

3 - Go back to school

Going back to college to get a master's degree will cost O'Keefe more money, but it will allow him to defer $28,000 in student loans until 2017. He doesn't expect to take on more student loans while getting the advanced degree, and plans on starting to pay down some of the interest on some of the loans in the fall.

By deferring the loans - which can be done for at least two years - returning students don't have to count the student loans as debt, which will lower their debt-to-income ratio, Parsons says.

4 - Get a co-signer

A parent or relative can co-sign for a mortgage loan, making them responsible for payments if the young homeowner doesn't make them. The parents' income and liabilities are factored into the loan calculation, which should make it easier to get the loan.

O'Keefe's uncle co-signed his home loan, putting his uncle on the spot if O'Keefe doesn't make the $1,050 monthly payment.

5 - Buy a home you can afford

Even for students who aren't earning much money, buying a home can make more financial sense than paying rent, Parsons says.

"It costs less to own a house on a monthly basis than to rent the same place," even when insurance, maintenance and other costs are included, he says. Mortgage interest can be written off on most tax returns, which drops the cost of homeownership, he says.

O'Keefe is buying what he calls "good value at a good time," and his mortgage is about $250 less per month than what he'd be paying in rent. The 3.25% interest rate he's paying on a 30-year fixed mortgage should be paying rent increases, he says.

If things get really bad and he loses his job, O'Keefe figures he'll still be better off as a homeowner than as a renter. He has a simple backup plan if he's in a pinch for cash - rent out one of the four rooms in his house.