For a short summary:
It takes into account every tower that's on your base and then multiplied by research, runes, rider buff and monument. Any changes to your base will affect your defense power. It will not always display your highest defense power. It will go down if you move it to a different island that is providing less than its original place.
For a detailed explanation:
Research - This are always active in your base and will always increase the defense power value of each tower that you have on your base
Rune - This affects all towers that is covered by a monument. Regardless if the rune / glyph is actually improving the tower's attack / health / supershot / attack speed, its defense power will increase. This also means that if you switch out your towers to a different island where the rune rarity there is different, your defense power may go up and down depending on the difference. If there's 5 exotic on both island, then no changes will take place. If there's a legendary on one side, your defense power may go down.
Rider Buff - This affects your defense power by a lot depending on how good is your rider equipment. For reference, a Rider with 120% ATK/HP can increase a level 100 tower's defense power which is around 800M~1B. If you notice that your base and your friend's base is the same, but he/she has a higher defense power, then this is the deciding factor on why his/her base is better.
Monument - This should be self explanatory. Activating your monument boost all towers it is covering by 30% ATK/HP. Seasonal boost are always active during the season and expires on the last week on Wednesday 12:00 AM PT.
Common player mistakes on why their defense power went down
1. Suddenly unequipping a gear / switching gear to a lower value or different type (ie. Using Dragon ATK/HP Gear on a Perched Rider)
2. Different Dragon type
3. Different Dragon Rider
4. Rider not completely bonded and immediately placed on the perch
5. Monuments expired
6. After a season has ended, seasonal boost expired
7. During Fortification, Tower still upgrading (note that their defense power is not added to your total while upgrading)
8. Placing a tower to a different island (Not all placement change will have the same defense power)
Issues with Defense Power
1. A tower upgrade may sometimes not deduct your total defense power until you restart the game or boost your monument (this forces the game to update your defense power)
2. Changes to Perch Building may sometimes not show the correct defense power until a force restart or a boost to your monument (ie. Removing perched dragon may not reduce your defense power until you do the fix)
3. Much like #1, if you immediately complete your tower upgrade, you sometimes get double its defense power. First was supposed to be deducted due to upgrading it and the second is the new defense power being added. Restarting the game or boosting a monument should fix this visual bug
Further explanation on why your defense power goes down HERE