So first of all, there is no universal definition for cost per flight hour; there's a classic SAAB presentation for example where they claimed (around a decade ago IIRC) that the F-16C (when comparing it to the Gripen C) cost $7,000/hr. In contrast, the USAF generally claims the F-16C costs around $25,000K/hr. The vast difference between those two numbers comes from what's being included / excluded in those figures.
Here's a graphical comparison for example of CPFH types used with regards to the F-35; you can find a greater breakdown of these different cost elements in this CAPE document:
https://www.cape.osd.mil/files/os_guide_v9_march_2014.pdf
Total ownership / total O&S can be a bit odd in that, while it does ultimately capture the total cost of operating a fleet, it includes things you might not have thought of, such as (under "Indirect costs" / "indirect support") medical support / services, initial recruit / officer training, etc.
View attachment 677102
For the SAAB $7K/hr F-16C figure, they'd be talking about something akin to the Reimbursable CPFH described above (
and for comparison's sake, here's the FY2021 reimbursable figures for the US services' fleets), whereas the USAF and a number of other military services around the world are generally referring to ownership or total ownership CPFH.
As for how CPFH itself is calculated, it's generally just the annual sustainment cost for a fleet, divided by the annual flight hours. The "fleet" in equation can be individual squadrons / units, but generally it's for an entire service's fleet of that aircraft type. For the F-35A CPFH figures you see it's generally just the USAF's F-35A total ownership CPFH; other F-35A operators that publicly report sustainment costs (like Australia) have had fairly similar costs, sometimes lower.
And as for how Lockheed can claim a certain CPFH by a certain date; the short answer is that they can't be 100% certain, but with the F-35 and Lockheed they were awarded a 3-year sustainment contract by the US last year, and so now Lockheed has the power to tell their suppliers that X amount of work has been secured and certain efficiencies can be gained by optimising logistics, investing in tooling and equipment, etc. However, Lockheed and its contractors / suppliers / partners do not perform all F-35 maintenance.
Out of the $33K/hr CPFH that we see for an F-35A today, Lockheed only controls around 39% of that while Pratt & Whitney (who contract to the US independently of Lockheed) owns another 11% and the US military is responsible for the other ~50%. So when Lockheed says that it's going to drop the CPFH of an F-35A from $33K to $30K by 2023, they're talking about what they can achieve by reducing their 39% of sustainment costs. In contrast, the "$25K/hr by 2025" F-35A CPFH goal that Lockheed was talking about a year or two ago is what Lockheed claims is possible, but is reliant on both P&W and the USAF reducing their F-35A sustainment costs by around 15% (from around $20K/hr [of the $33K/hr total] today to around $17K/hr [of the $25K/hr total]). Lockheed can influence USAF costs a little bit (eg: if ALIS / ODIN is less buggy then the USAF spends fewer man-hours fixing the jet and can fly the jet more frequently), but it's mostly not up to them.