The D Flip-Flop (Quickstart Tutorial) (2024)

The D Flip-Flop is an edge-triggered circuit that combines a pair of D latches to store one bit. It is commonly used as a basic building block in digital electronics to create counters or memory blocks such as shift registers.

In this tutorial, you will learn how it works, its truth table, and how to build one with logic gates.

The D Flip-Flop (Quickstart Tutorial) (1)

What is a Flip-Flop?

Latches and flip-flops are sometimes grouped together since they both can store one bit (1 or 0) on their outputs. In contrast to latches, flip-flops are synchronous circuits that need a clock signal (Clk). The D Flip-Flop will only store a new value from the D input when the clock goes from 0 to 1 (rising edge) or 1 to 0 (falling edge).

A D Flip-Flop is built from two D latches. You can see a D Flip-Flop that updates on the rising edge below:

The D Flip-Flop (Quickstart Tutorial) (2)

The timing diagram for this circuit is shown below. It shows how a rising edge-triggered D Flip-Flop behaves. The output Q only changes to the value the D input has at the moment the clock goes from 0 to 1.

The D Flip-Flop (Quickstart Tutorial) (3)

How Does the D Flip-Flop Work?

Since the output Q only changes when the Clock input goes from 0 to 1, you’ll get the following truth table:

(no change)
0→1 (↑)00Reset Q to 0
0→1 (↑)11Set Q to 1
(no change)

In the first and last rows of the truth table, the clock input is 0 and 1. None of them is a rising edge signal, so nothing happens. The Q output keeps whatever value it had. In this case, no matter what value the D input has, the Q output won’t change, it will keep its value as it is. This is how this circuit “remembers” a bit.

Have a look at the two middle rows. Here the clock input is going from 0 to 1, so you have a rising edge. This means that if the D input is 0, the Q output will be reset to 0. If the D input is 1, the Q output will be set to 1.

The D Flip-Flop (Quickstart Tutorial) (4)

Get Our Basic Electronic Components Guide

Learn how the basic electronic components work so that circuit diagrams will start making sense to you.


D Flip-Flops that you find in chips ready for use, such as the CD4013, usually also have Set and Reset inputs that you can use to force the D flip-flop into starting with a 1 or a 0 on the output. Using these pins is sometimes referred to as “presetting” the D flip-flop.

The Advantage of a D Flip-Flop vs Latch

The D Flip-Flop (Quickstart Tutorial) (5)

One of the downsides of the D latch is that its output can change at any time while its Enable pin is 1. So if you apply a clock signal to the D Latch, the Q output could also change during the time the positive pulse lasts.

In the timing diagram above, you can see that during one clock cycle, the output is both 1 and 0 because the D input changes during the clock pulse. That’s something you don’t want to happen in a clocked digital system.

To get this flip-flop to change its output only on the rising edges of the clock signal you can build a Master-Slave D Flip-Flop Circuit, which requires a combination of two D latches as follows:

The D Flip-Flop (Quickstart Tutorial) (7)

How D Flip-Flops Work

The output from the master latch changes to what the D input has when the Clk input is 0.

If Clk is 0, it means that the Enable input of the slave latch is also 0. So nothing happens with the output of this latch.

But at the moment that Clk goes from 0 to 1 (rising edge), the Enable input of the slave latch is set to 1. That means whatever was on the output of the master latch at the moment Clk went from 0 to 1 is saved to the output of the slave latch.

If you substitute the symbols for D latches built with NAND gates you’ll get:

The D Flip-Flop (Quickstart Tutorial) (8)

What Can You Use Them For?

The D Flip-flop is a very useful circuit. You can combine several D flip-flops to create for example shift registers and counters, which are used a lot in digital electronics. But you don’t have to build them from scratch. Instead, you can use the CD4013 chip that contains two D flip-flops.

Circuit Example: Shift Registers

To create a shift register, connect the output of one flip-flop to the input of the next. New bits go into the first flip-flop on the left. And for every clock pulse, the bits stored in the other flip-flops are shifted one place to the right.

The D Flip-Flop (Quickstart Tutorial) (9)

This is useful for example to get more output pins from an Arduino or other microcontroller. To control a shift register, you need one data pin and one clock pin. So with only two pins from the Arduino, you can control as many external pins as you want by using a shift register.

Circuit Example: Ring Counters

If you take the output from the last flip-flop in a shift register and connect it to the input of the first flip-flop, you get aRing Counter. Preset one of the flip-flops to start with 1, then this 1 will be shifted around and around in the Ring Counter.

The D Flip-Flop (Quickstart Tutorial) (10)

TheIC 4017is a chip with this type of functionality, but with 10 outputs instead of just 4 like above. This makes for a fun chip you can use for example to create the Knight Rider LED bar.


Do you have any questions about how the D Flip-Flop works? Let me know in the comments below.

More Digital Electronics Tutorials

  • The Binary Number System
  • Logic Gates: AND, OR, NOT, NAND, NOR, XOR, XNOR
  • The S-R Latch
  • The D Latch
  • The D Flip-Flop
  • The JK Flip-Flop
  • The T Flip-Flop
  • The Shift Register
  • Binary Adders: The Half Adder
  • Binary Adders: The Full Adder
  • How To Use Open Collector Outputs
  • 4000 Series IC Tutorials
  • 7400 Series IC Tutorials

The D Flip-Flop (Quickstart Tutorial) (11)

10 Simple Steps to Learn Electronics

Electronics is easy when you know what to focus on and what to ignore. Learn what "the basics" really is and how to learn it fast.

The D Flip-Flop (Quickstart Tutorial) (2024)
Top Articles
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 6159

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.