Factors that go into the cost of solar panel installation include city or state rebates, a federal tax credit, how much sun you typically get and the rate your solar contractor charges per watt. Additionally, installation costs depend on how much energy you use. 
Solar panel installation costs are typically quoted per watt of energy the array will provide. Depending on your location and the complexity of your system, prices can range from $0.03 to $0.08 per watt.
The average United States house uses about 900 kilowatt-hours per month. The less energy you use, the less you’ll need to spend on solar panels. You can find your average kWh per month on your electrical utility bill. Divide this number by 30 to get your average daily energy use. Then divide that number by the average hours of peak sunlight you receive each day to get the amount of energy, in kilowatts, your solar panel array will have to provide. One kilowatt is worth one thousand watts, so multiply this by 1000. Multiply the final number by the installation cost per watt quoted by your solar panel contractor to get the total solar panel cost.
In simple mathematical terms: Gross Cost = ((average kWh/month) * 1000 * (contractor cost per watt))/(30 * (hours of peak sunlight per day)).
Location, Location, Location – Peak Sunlight
Depending on where you live, you will receive more peak sunlight per day. This means that if you want to power all of your electrical needs through solar panels, it will be less expensive to do so in the sunnier parts of the country.
If you live in Arizona, New Mexico and parts of California, Nevada and Texas, you will receive about 6-7 hours of peak sunlight per day. If you live in most states in the Wild West like Colorado, Wyoming, Oklahoma, Utah, or Kansas, as well as southern states like Texas, Florida and Georgia, you will receive about 5-6 hours of peak sunlight per day. Most states receive 4-5 hours per day. 
Cost per watt is determined by a variety of elements, including solar panel technology, price of production and price of labor. Because most contractors don’t post their rates online directly, you will need to call several and compare quotes.
The good news is that solar panel technology and production are getting more efficient every year; it is getting easier for contractors to get a hold of cheap, powerful solar panels. These efficiency gains will translate into savings for you. Just a few years ago, the average price was about $7 per watt for solar panel installation. Now it’s closer to $5.
City, State and Federal Rebates and Credits
When calculating the cost of your solar system, you also have to keep in mind that many cities and states offer you rebates for installing solar panels. Rebates are given per watt of energy, and they may reach levels up to $4 per watt. The average rebate is around $2 per watt. However, not everyone is eligible for these state and local rebates. City and state rebates may be found at the Database of State Incentives for Renewables and Efficiency.  You are also eligible for a federal tax credit for 30% of your total purchase, applied after the city/state rebate. This means that you are only liable for 70% of any price you’re quoted for solar installation.
You can find the actual cost by multiplying the gross cost by the rebate amount per watt over the contractor cost per watt and multiplying again by 0.7.
In strict mathematical terms, this comes to: Actual Cost = Gross Cost * (rebate per watt / contractor cost per watt) * .7
Total Cost Conclusion
There are many variables that go into your solar panel costs. However, if we plug all the average values in to the equation, we get:
Gross Cost = (900 * 1000 * 5) / 30 * 5 = $30,000
$30,000 is the average cost that most websites quote for solar panel installation. However, when you factor in rebates and tax credits, the true average cost is closer to:
Actual Cost = 30000 * (2/5) * 0.7 = $8,400
Keep in mind that the majority of savings here come from the rebate. If your city or state does not offer solar rebates, you may have to pay closer to $20,000 on average. If you use significantly higher amounts of energy, if you live in a low-sunlight area or if your contractor is particularly expensive, you may have to pay more as well.