I have no experience pricing flights from the west coast, but Google Flights is showing things in the $1300-1500 range now, which I find painful. If you can get to LAX, there are $600-800 options. There's even a non-stop outbound on a ticket with a total price of $863. Understand that all of the prices may be different tomorrow; that's life in Airfare World. You'll note that a lot of the routings will get you into Madrid fairly late. Arrival day is often rather worthless anyway because of sleep-deprivation and jetlag, so a late arrival sometimes just means fewer hours before you can go to sleep on your new schedule. It would be important, however, not to arrive so late that you couldn't get into your lodgings, whatever they may be. So that's something to be very careful about.
I haven't stayed in a hostel since the early 1970s, and I know they do vary. However, I think all have lockers (travel with a good lock) for stowing your belongings. Petty theft is possible. Personal safety wouldn't be a concern of mine. I'd read all the English-language reviews of the places you are considering on booking.com or whatever website you use. I'm sure there are others that are useful for hostels, but I do not know what they are.
The way to handle money during the trip is pretty much the same way you probably do at home: Pay for things with credit cards when you can, and use your ATM card in Spanish ATMs to withdraw money from your bank account at home when you need cash.
The money you get from the ATMs will be euros; you will get a good exchange rate. Do not even think of trying to change physical US dollar bills into euros. You'll have a hard time finding a place to do that, and the exchange rate will be quite bad. You may want to take a bit of American money just in case of an emergency (such as your ATM card doesn't work). I'd keep that to no more than $100 (unless you might need more to get home from LAX), and you need to figure out where you're going to store that probably-never-to-be-used money. It should not be in your wallet; I don't care what pocket you put your wallet in, it will be fair game for the immensely talented European pickpockets, so it should never contain more than a small amount of money.
There are other things you need to know, but I think these are they key ones:
Notify your bank and your credit-card issuers (numbers are on backs of cards) of your travel plans so they don't suspect fraud when you start using the cards in Spain.
Find out what extra fees you may face for using your ATM or credit card overseas. If one has more fees than the other, that's information that might affect how you choose to pay for things if you have an option. But your trip is short, you've indicated that you're on a budget, and I don't think the total fees you will encounter justify trying to open new accounts between now and March.
Always complete your transactions (ATM or credit card) in euros. Any time you allow a hotel/hostel/restaurant/store/ATM to charge you in dollars, you are wasting money, because they get to decide what (dreadful) exchange rate they will give you.
Read Rick's tips on money here: Rick's Money Tips. A lot more could be said, but this comes up all the time, and there's really no need to reinvent the wheel. If you have questions about something you've read (or that I've said here), come back and ask.