Given the market of the last decade, investing everything above the 30-40k expenses and income tax in the S&P500 and re-investing the dividends would have brought GP there. Not really sure about how one can make it with 30-40k including rent in the Bay Area, but this sounds like the most reasonable takeaway for most readers.
Prior to covid, find apartment within 30 biking to work, get two bedroom, split with roommate.
Going out $150/month
Limit yourself to going out with coworkers once a week, social gatherings once a week and a rule of only buying one drink while out.
Groceries & clothes $400/m
Make all your meals at home unless your work offered fully subsided meals and or on specific days subsided meals.
For clothing, only buy once the piece no longer serves it's function. Do not buy simply because it looks good or it has some "new feature".
Subscriptions $70/m
Netflix, Spotify, GitHub, Youtube Red, and Audible.
Books $50/m
Libraries are a good saving spot here but sometimes you're unable to get some of the new technical books.
Bike maintenance $500/yr
You're going to put wear and tear onto the trusty bike.
Remaining $0-10k/Yr
Yolo. Flights back to see family. Replacement bike if it gets stolen. Random transit trips to see friends.
Free beer, pizza and get to meet interesting people.
You might as well get the advice "marry rich" - it's probably more likely.
Debt is a killer. I used to have a lot of credit card and personal debt, and was paying over $1,500/mo in interest on less than $100k USD/year. If you get stuck in that trap it's damn near impossible to get out of if you overextend yourself.
A lot of folks grossly underestimate what they spend eating out and drinking. Probably less of a problem now than a few years ago, but coinciding with my credit card debt phase I would have told you I spent "$100, maybe $150" a month when it was closer to $400-500.
If you're not set up for retirement (see below) there's little to no reason to be leasing a brand new BMW. I was absolutely guilty of this and it's tens of thousands of dollars I essentially set on fire for three years. You don't even have to sacrifice the nice car, my 2016 5 series was less than $25k out the door and I got it right after someone turned it in off-lease. My payment is less than theirs was and it'll be paid off before the warranty runs out. I'll then have an "asset" (not really) worth $5-10k, and can get another $25k off-lease car which will cost me less and get paid off quicker, if not in cash.
If you max out your 401(k) you are saving about $20k/yr while only reducing your taxable income by ~$15k/yr depending on your marginal tax rate. A Roth adds another $6k to that if you're under the cap (something like $140k for 2020) and you can withdraw the contributions from that account at any time without penalty. Not helpful for someone making $40k/yr but if you're making $100k it's hard to make a good argument not to max out your retirement unless you live in one of the outlier cities as far as rent and expenses.
There are absolutely the /r/personalfinance types who act like if you go to a restaurant more than once every six months you're going to end up destitute and starving while homeless. And the FIRE community is a borderline cult. But nobody working in our industry, even in super high-COL areas, really has to worry about retirement, even if they've made dumb mistakes like I did that ended up costing hundreds of thousands in the long run.
Even if you are above the Roth cap, you can contribute post-tax $6k to a tradtional IRA, then immediately roll into a Roth IRA. This is known as a "backdoor Roth".
Additionally, some employer 401(k) plans allow you to contribute post-tax money to your 401(k). The IRS specifies an upper limit of the total of [employee pre-tax + employer match + employee post-tax], which was $57k in 2020. The post-tax portion of the above can also be rolled into a Roth IRA. This is commonly referred to as the "mega-backdoor Roth"
Also, don't forget catch-up contributions to each if you are over 50.
Point is if you have the income to support it, you can save much more in a tax advantaged way than just that $19.5k pre-tax 401(k). Please look up the tax consequences of any of these options before doing them. They are straightforward but contain a few pitfalls, such as the pro-rata rule affecting rolling over traditional IRAs into Roth IRAs.