Bach was born in 1685 in Eisenach, in the duchy of Saxe-Eisenach, into an extensive musical family. His father, Johann Ambrosius Bach, was the director of the town musicians, and all of his uncles were professional musicians. His father probably taught him to play the violin and harpsichord, and his brother Johann Christoph Bach taught him the clavichord and exposed him to much of the contemporary music.

Bach's mother died in 1694, and his father died eight months later.

The 10-year-old Bach moved in with his eldest brother, Johann Christoph Bach (1671–1721), the organist at St. Michael's Church in Ohrdruf, Saxe-Gotha-Altenburg. There he studied, performed, and copied music, including his own brother's, despite being forbidden to do so because scores were so valuable and private, and blank ledger paper of that type was costly.

By 3 April 1700, Bach and his schoolfriend Georg Erdmann—who was two years Bach's elder—were enrolled in the prestigious St. Michael's School in Lüneburg, some two weeks' travel north of Ohrdruf.

While in Lüneburg, Bach had access to St. John's Church and possibly used the church's famous organ from 1553, since it was played by his organ teacher Georg Böhm.

In January 1703, shortly after graduating from St. Michael's and being turned down for the post of organist at Sangerhausen, Bach was appointed court musician in the chapel of Duke Johann Ernst III in Weimar.

In August 1703, he became the organist at the New Church, with light duties, a relatively generous salary, and a new organ tuned in a temperament that allowed music written in a wider range of keys to be played.

Despite strong family connections and a musically enthusiastic employer, tension built up between Bach and the authorities after several years in the post. Bach was dissatisfied with the standard of singers in the choir. He called one of them a "Zippel Fagottist" (weenie bassoon player). Late one evening this student, named Geyersbach, went after Bach with a stick. Bach filed a complaint against Geyersbach with the authorities. They acquitted Geyersbach with a minor reprimand and ordered Bach to be more moderate regarding the musical qualities he expected from his students. Some months later Bach upset his employer by a prolonged absence from Arnstadt: after obtaining leave for four weeks, he was absent for around four months in 1705–1706 to visit the organist and composer Dieterich Buxtehude in the northern city of Lübeck. The visit to Buxtehude involved a 450-kilometre (280 mi) journey each way, reportedly on foot.

In 1706, Bach applied for a post as organist at the Blasius Church in Mühlhausen.

Bach's earliest cantatas date from his years in Arnstadt and Mühlhausen. The earliest one with a known date is Christ lag in Todes Banden, BWV 4, for Easter 1707, which is one of his chorale cantatas. Gottes Zeit ist die allerbeste Zeit, BWV 106, also known as Actus Tragicus, is a funeral cantata from the Mühlhausen period. Around 20 church cantatas are extant from his later years in Weimar, for instance, Ich hatte viel Bekümmernis, BWV 21.

As part of his application, he had a cantata performed on Easter, 24 April 1707, likely an early version of his Christ lag in Todes Banden.

Bach married Maria Barbara Bach, his second cousin.

In 1708 Bach wrote Gott ist mein König, a festive cantata for the inauguration of the new council, which was published at the council's expense.

Bach left Mühlhausen in 1708, returning to Weimar this time as organist and from 1714 Konzertmeister (director of music) at the ducal court, where he had an opportunity to work with a large, well-funded contingent of professional musicians.

Bach also started work on the Little Organ Book in Weimar, containing traditional Lutheran chorale tunes set in complex textures.

Later the same year, their first child, Catharina Dorothea, was born, and Maria Barbara's elder, unmarried sister joined them. Johann Sebastian and Maria Barbara had three more children, who however did not live to their first birthday, including twins born in 1713.

In Weimar, Bach continued to play and compose for the organ and perform concert music with the duke's ensemble. He also began to write the preludes and fugues which were later assembled into his monumental work The Well-Tempered Clavier ("clavier" meaning clavichord or harpsichord), consisting of two books, each containing 24 preludes and fugues in every major and minor key.

In 1713, Bach was offered a post in Halle when he advised the authorities during a renovation by Christoph Cuntzius of the main organ in the west gallery of the Market Church of Our Dear Lady.

In the spring of 1714, Bach was promoted to Konzertmeister, an honour that entailed performing a church cantata monthly in the castle church. The first three cantatas in the new series Bach composed in Weimar were Himmelskönig, sei willkommen, BWV 182, for Palm Sunday, which coincided with the Annunciation that year; Weinen, Klagen, Sorgen, Zagen, BWV 12, for Jubilate Sunday; and Erschallet, ihr Lieder, erklinget, ihr Saiten! BWV 172 for Pentecost.

In 1717, Bach eventually fell out of favor in Weimar and, according to a translation of the court secretary's report, was jailed for almost a month before being unfavorably dismissed: "On November 6, [1717], the quondam concertmaster and organist Bach was confined to the County Judge's place of detention for too stubbornly forcing the issue of his dismissal and finally on December 2 was freed from arrest with notice of his unfavourable discharge."

Leopold, Prince of Anhalt-Köthen, hired Bach to serve as his Kapellmeister (director of music) in 1717. Prince Leopold, himself a musician, appreciated Bach's talents, paid him well and gave him considerable latitude in composing and performing. The prince was a Calvinist and did not use elaborate music in his worship; accordingly, most of Bach's work from this period was secular, including the orchestral suites, cello suites, sonatas and partitas for solo violin, and Brandenburg Concertos.

Bach also composed secular cantatas for the court, such as Die Zeit, die Tag und Jahre macht, BWV 134a.

Despite being born in the same year and only about 130 kilometres (80 mi) apart, Bach and Handel never met. In 1719, Bach made the 35-kilometre (22 mi) journey from Köthen to Halle with the intention of meeting Handel; however, Handel had left the town. In 1730, Bach's oldest son, Wilhelm Friedemann, travelled to Halle to invite Handel to visit the Bach family in Leipzig, but the visit did not take place.

On 7 July 1720, while Bach was away in Carlsbad with Prince Leopold, Bach's wife suddenly died.

The following year, Bach met Anna Magdalena Wilcke, a young, highly gifted soprano 16 years his junior, who performed at the court in Köthen; they married on 3 December 1721.

Johann Kuhnau had been Thomaskantor in Leipzig from 1701 until his death on 5 June 1722. Bach had visited Leipzig during Kuhnau's tenure: in 1714 he attended the service at the St. Thomas Church on the first Sunday of Advent, and in 1717 he had tested the organ of the Paulinerkirche. In 1716 Bach and Kuhnau had met on the occasion of the testing and inauguration of an organ in Halle.

In 1723, Bach was appointed Thomaskantor, Cantor of the Thomasschule at the Thomaskirche (St. Thomas Church) in Leipzig, which provided music for four churches in the city: the Thomaskirche and Nikolaikirche (St. Nicholas Church) and to a lesser extent the Neue Kirche (New Church) and Peterskirche (St. Peter's Church).

Bach's predecessor as cantor, Johann Kuhnau, had also been music director for the Paulinerkirche, the church of Leipzig University. But when Bach was installed as cantor in 1723, he was put in charge only of music for festal (church holiday) services at the Paulinerkirche; his petition to also provide music for regular Sunday services there (for a corresponding salary increase) went all the way to the Elector but was denied.

The first version of Bach's Magnificat dates from 1723, but the work is best known in its D major version of 1733.

Bach usually led performances of his cantatas, most of which were composed within three years of his relocation to Leipzig. The first was Die Elenden sollen essen, BWV 75, performed in the Nikolaikirche on 30 May 1723, the first Sunday after Trinity. Bach collected his cantatas in annual cycles. Five are mentioned in obituaries, three are extant.

The St John Passion was the first Passion Bach composed during his tenure as Thomaskantor in Leipzig.

Of the more than 300 cantatas which Bach composed in Leipzig, over 100 have been lost to posterity. Most of these works expound on the Gospel readings prescribed for every Sunday and feast day in the Lutheran year. Bach started a second annual cycle the first Sunday after Trinity of 1724 and composed only chorale cantatas, each based on a single church hymn. These include O Ewigkeit, du Donnerwort, BWV 20, Wachet auf, ruft uns die Stimme, BWV 140, Nun komm, der Heiden Heiland, BWV 62, and Wie schön leuchtet der Morgenstern, BWV 1.

After this, in 1725, Bach "lost interest" in working even for festal services at the Paulinerkirche and appeared there only on "special occasions".

With its double choir and orchestra, the St Matthew Passion is one of Bach's most extended works.

In 1733, Bach composed a Kyrie–Gloria Mass in B minor which he later incorporated in his Mass in B minor. He presented the manuscript to the Elector in an eventually successful bid to persuade the prince to give him the title of Court Composer.

In 1735 Bach started to prepare his first publication of organ music, which was printed as the third Clavier-Übung in 1739.

From 1740 to 1748 Bach copied, transcribed, expanded or programmed music in an older polyphonic style (stile antico) by, among others, Palestrina (BNB I/P/2), Kerll (BWV 241), Torri (BWV Anh. 30), Bassani (BWV 1081), Gasparini (Missa Canonica) and Caldara (BWV 1082).

Two large-scale compositions occupied a central place in Bach's last years. From around 1742 he wrote and revised the various canons and fugues of The Art of Fugue, which he continued to prepare for publication until shortly before his death.

After extracting a cantata, BWV 191, from his 1733 Kyrie-Gloria Mass for the Dresden court in the mid 1740s, Bach expanded that setting into his Mass in B minor in the last years of his life. Although the complete mass was never performed during the composer's lifetime, it is considered to be among the greatest choral works in history.

In 1746 Bach was preparing to enter Lorenz Christoph Mizler's Society of Musical Sciences. In order to be admitted Bach had to submit a composition, for which he chose his Canonic Variations on "Vom Himmel hoch da komm' ich her", and a portrait, which was painted by Elias Gottlob Haussmann and featured Bach's Canon triplex á 6 Voc.

In May 1747, Bach visited the court of King Frederick II of Prussia in Potsdam. The king played a theme for Bach and challenged him to improvise a fugue based on his theme. Bach obliged, playing a three-part fugue on one of Frederick's fortepianos, which was a new type of instrument at the time. Upon his return to Leipzig he composed a set of fugues and canons, and a trio sonata, based on the Thema Regium (theme of the king).

In January 1749, Bach's daughter Elisabeth Juliane Friederica married his pupil Johann Christoph Altnickol. Bach's health was, however, declining.

On 2 June, Heinrich von Brühl wrote to one of the Leipzig burgomasters to request that his music director, Johann Gottlob Harrer, fill the Thomaskantor and Director musics posts "upon the eventual ... decease of Mr. Bach".

Becoming blind, Bach underwent eye surgery, in March 1750 and again in April, by the British eye surgeon John Taylor, a man widely understood today as a charlatan and believed to have blinded hundreds of people.

Bach died on 28 July 1750 from complications due to the unsuccessful treatment.

In 1802, Johann Nikolaus Forkel published Johann Sebastian Bach: His Life, Art, and Work, the first biography of the composer, which contributed to his becoming known to a wider public.

In 1950, Wolfgang Schmieder published a thematic catalogue of Bach's compositions called the Bach-Werke-Verzeichnis (Bach Works Catalogue). Schmieder largely followed the Bach-Gesellschaft-Ausgabe, a comprehensive edition of the composer's works that was produced between 1850 and 1900. The first edition of the catalogue listed 1,080 surviving compositions indisputably composed by Bach.

In the 21st century, Bach's compositions have become available online, for instance at the International Music Score Library Project. High-resolution facsimiles of Bach's autographs became available at the Bach digital website. 21st-century biographers include Peter Williams and the conductor John Eliot Gardiner.