There's not really a straightforward answer to that. I started semi-consistantly writing fanfics for the purpose of posting them online in fanfic spaces in August 2021, but those were not the first fanfics I did. Particularly depending on how loose your definition of fanfic is.
I know for sure that in 2007 or 2008 I made a short lived attempt at a story with myself and my friend as Pokemon trainers (with a premise that was Black and White before Black and White came out), that was fanfic-adjacent. But I also tried doing webcomics from 2005-2009 that either involved video game characters (without really being about them) or were just parodies of whatever games I happened to have been playing at the time. I will not elaborate on further for reasons I hope you can understand.
And before then I often playacted with myself a number of stories involving different aspects of video games and anime and books I liked that I came up with on the spot (and probably made me look extremely bully-able to observers) and thankfully don't remember many details of. And before then, back when I was in first grade, I tried making storybooks based on Yoshi's Story with computer paper and markers.
So uh. Depending on how you wanna define fanfic, I started in either 2021, 2007, 2005, 2001, or 1998.
As for writing in general, well. I kinda answered a similar question a couple months ago on Tumblr. Short version is, I've kinda been writing in one way or another for most of my life and it all just kinda added up over the years by complete accident. I hope that's a semi-satisfactory answer?
Truth is, as is the case with any form of creative media, you don't start being good at it. Nobody is good at their medium when they start. But they kept trying and trying and trying, improving their work little by little over many years. I feel like five years are pretty good benchmarkers for seeing how far you've come on anything you've worked at regularly.

