They are a combination of the prices the stocks in them (or at least, changes in them), but not a simple sum. Each index is different and their calculation methodologies are publicly available.
The Dow Jones Industrial Average (currently owned by S&P) is an old-style index that was originally simply the arithmetic average of 30 stocks...easy enough to calculate by hand. However, they didn't want the DJIA falling because of stock splits and other corporate actions, so now that average is divided by the Dow Divisor.
The S&P 500 is a value-weighted return index of 500 of the largest US companies. The initial level was 10 (an arbitrary starting point). Each month its return goes up by a percentage equal to the percentage return in the value-weighted portfolio of its constituents. The index level is not directly tied to prices, only returns. Notice also that contrary to popular belief, the S&P 500 is not a total return index, which means the return it gets does not include the effects of the dividends paid by its constituents. S&P also publishes a total return version that is used for benchmarking mutual funds. More details on the calculation here, if you are interested.
The Nasdaq Composite is a value-weighted return index, similar to the S&P500, but its constituents are all stocks listed on the Nasdaq. Some details here and others available if you keep googling. The original level (in 1971) was 100. Like the S&P, the standard "Nasdaq" we see reported is not a total return index, though Nasdaq does publish a total return version.
The S&P and Nasdaq also have a divisor to correct for corporate actions (so the indices don't fall when there is a stock split, for example).