Samberg was born in Berkeley, California, as David A. J. Samberg, but changed his first name to Andy at age five. His mother, Marjorie "Margi" (née Marrow), is an elementary school teacher, and his father, Joe, is a photographer. He has two sisters, Johanna and Darrow. He is Jewish, although he describes himself as "not particularly religious." His maternal grandfather, industrial psychologist and philanthropist Alfred J. Marrow, served as the executive chair of the American Jewish Congress. Samberg is a third cousin of U.S. Senator Tammy Baldwin, as their maternal grandfathers were first cousins. He attended elementary school with his Brooklyn Nine Nine co-star Chelsea Peretti. Samberg discovered Saturday Night Live as a child, while sneaking past his parents to watch professional wrestling on television. He was obsessed with the show and his devotion to comedy was frustrating to teachers who felt he was distracted from his schoolwork. Samberg graduated from Berkeley High School in 1996, where he became interested in creative writing and has stated that "[writing classes] were the ones that I put all my effort into... that's what I cared about and that's what I ended up doing." He attended college at University of California, Santa Cruz for two years before transferring to New York University's Tisch School of the Arts, where he graduated in 2000.
Samberg majored in experimental film, including the music video for James Kochalka's song "Monkey vs. Robot" as Monkey. He became a YouTube and internet star and made his own comedy videos with his two friends Akiva Schaffer and Jorma Taccone. When YouTube was created in 2005, the streaming of their videos became much more widespread over the internet. Samberg became a featured player on SNL in part because of the work he had done on their sketch comedy website TheLonelyIsland.com, which helped them land an agent and eventually get hired at SNL. Prior to joining its cast, Samberg was (and remains) a member of the comedy troupe The Lonely Island (along with Taccone and Schaffer). The trio began writing for Saturday Night Live in 2005 and released their debut album, Incredibad in 2009. Samberg appeared in numerous theatrical films, commercials, music videos and hosted special events, including the 2009 MTV Movie Awards. In 2012, Samberg delivered the Class Day speech at Harvard University, and starred with Adam Sandler in That's My Boy and Hotel Transylvania (a role he reprised for Hotel Transylvania 2). In September 2012, Samberg played Cuckoo in the BAFTA nominated BBC Three series Cuckoo, and currently stars as Detective Jake Peralta in FOX's police sitcom Brooklyn Nine-Nine which first aired on September 17, 2013, for which he won the Golden Globe Award for Best Actor – Television Series Musical or Comedy in 2014.
Samberg hosted the 67th Primetime Emmy Awards on September 20, 2015, during which in his opening monologue, he referred to U.S. presidential candidate Donald Trump as possibly being racist, telling the studio and television audience "Well, I've gotta say, sure, Donald Trump seems racist. Let's see what else?" and U.S. presidential candidate Bernie Sanders as having an unkempt appearance: "Is it just me or does Bernie Sanders always seem like his flight is delayed? Guy’s a mess!"
Samberg starred in Sleater-Kinney's "No Cities to Love" video along with other celebrities such as Fred Armisen, Ellen Page, and Norman Reedus. On May 16, 2016, Samberg and the Lonely Island performed their 2009 hit "I'm on a Boat" with classroom instruments on The Tonight Show Starring Jimmy Fallon.
In September 2005, Samberg joined Saturday Night Live as a featured player along with his two friends as the show's writing staff. Though his live sketch roles were limited in his first year, he appeared in many prerecorded sketches including commercial parodies and various other filmed segments. On December 17, 2005, he and Chris Parnell starred in the Digital Short show "Lazy Sunday", a hip hop song performed by two Manhattanites on a quest to see the film The Chronicles of Narnia: The Lion, the Witch and the Wardrobe. The short quickly became an Internet phenomenon and garnered Samberg significant media and public attention, as did "Dick in a Box," a duet with Justin Timberlake that won a Creative Arts Emmy for Outstanding Original Music and Lyrics. His comedy troupe's collaboration with T-Pain, the "I'm on a Boat" music video had over 56 million views on YouTube, after debuting on February 7, 2009 and was nominated for a Grammy Award. Another digital short, "Motherlover" (also featuring Timberlake) was released on May 10, 2009 (to commemorate Mother's Day) and is a sequel of "Dick in a Box." Outside of his prerecorded segments, he also participated in recurring live segments, such as his Blizzard Man sketch. On June 1, 2012, Samberg's spokesperson announced that he had left the show. He returned to the show as the host on the Season 39 finale in 2014.
Samberg has described himself as a "superfan" of musician Joanna Newsom, whom he first met at one of her concerts. After five years of dating, Samberg proposed to her in February 2013, and they married on September 21, 2013 in Big Sur, California, with Saturday Night Live co-star Seth Meyers serving as the wedding's groomsman. In March 2014, Samberg and Newsom purchased the estate Moorcrest in the Beachwood Canyon area of Los Angeles, California. They also own a home in the West Village of Manhattan, New York.
On August 8, 2017, Samberg and Newsom welcomed their first child, a daughter.