The simple answer, you need cash. Cash is legal tender and if you do not have a ton of that like me then you need less cash and some form of credit. Your credit can be good or bad and in the same way your loan will be cheap or expensive, that's the downside to being a borrower. Historically you want to put 20% down but today some loans will go down to 15% or even 10% without having to pay principal mortgage insurance. There is a lot of unexpected cost with owning a home. I am going to assume you live with your parents or you are renting and that you have already explored the options of rent vs. owning. A primary residence or your the first home is usually the hardest but it does get easier. It get easier because owning your own property lets you accumulate equity as long as prices inflate and you can then use that equity as collateral to buy more homes.
When buying your first home unless you paying all cash you will be working with debt. Pay bad debt off first and in most cases start with the highest interest rate. Often that will be credit cards. So pay the Credit Card off and try and pay every month on time. Then the banks will want to see taxable income that they can base 43% of the loan from. In the CFPB own words "For example, if you pay $1500 a month for your mortgage and another $100 a month for an auto loan and $400 a month for the rest of your debts, your monthly debt payments are $2000. ($1500 + $100 + $400 = $2,000.) If your gross monthly income is $6000, then your debt-to-income ratio is 33 percent." Your debt-to-income ratio is all your monthly debt payments divided by your gross monthly income. This number is one way lenders measure your ability to manage the payments you make every month to repay the money you have borrowed.
Unexpected costs is a variable that can fluctuate with things like taxes, local municipalities, Home Owners Associations. So you want to factor in what you can and add 20% as an unknown. Watch out for tricky mortgage products like adjustable rates or ARM. There is nothing wrong with a 15 year fixed rate mortgage but as a precaution you can select a 30 year fixed rate mortgage. Your rate may be slightly higher than a 15 year but monthly mortgage payments will be half as much and you can always double your payments. There are certain situations where other mortgage products make sense but this is just a conventional method of acquiring real estate for the long haul.